Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Wheel of Fortune
- //Version : 02
- //MJ - 19-01-2020
- int delayTime = 50;
- int LEDS[10];
- int buttonpin = 13;
- bool startRolling = false;
- bool firstBatch = true;
- long randNumber;
- void setup()
- {
- Serial.begin(9600);
- pinMode(buttonpin, INPUT_PULLUP);
- randomSeed(analogRead(0));
- randNumber = random(0, 9);
- for (int i = 0; i <= 10; i++)
- {
- LEDS[i] = 2 + i;
- }
- shiftTab(LEDS, 10, randNumber);
- for (int j = 0; j <= 10; j++)
- {
- pinMode(LEDS[j], OUTPUT);
- digitalWrite(LEDS[j], LOW);
- }
- }
- void loop()
- {
- startRolling = false;
- delay(delayTime / 2);
- if (digitalRead(buttonpin) == LOW)
- {
- if(!firstBatch)
- {
- resetDraw();
- }
- startRolling = true;
- }
- else
- {
- startRolling = false;
- }
- if (startRolling)
- {
- rollLoop();
- }
- }
- void shiftTab(int tab[], int tabSize, int pos)
- {
- int teb[10];
- int counter = 0;
- int counterB = 0;
- for (int i = pos; i < tabSize; i++)
- {
- teb[counter] = tab[i];
- counter++;
- }
- if (counter != tabSize)
- {
- counterB = counter;
- for (int i = 0; i < tabSize - counter; i++)
- {
- teb[counterB] = tab[i];
- counterB++;
- }
- }
- for (int i = 0; i < tabSize; i++)
- {
- tab[i] = teb[i];
- }
- }
- void resetDraw()
- {
- shutALlDels();
- randNumber = random(0, 9);
- for (int i = 0; i <= 10; i++)
- {
- LEDS[i] = 2 + i;
- }
- shiftTab(LEDS, 10, randNumber);
- for (int j = 0; j <= 10; j++)
- {
- pinMode(LEDS[j], OUTPUT);
- digitalWrite(LEDS[j], LOW);
- }
- delayTime = 50;
- }
- void rollLoop()
- {
- int lastDel = 0;
- while (delayTime <= 650)
- {
- int x;
- delay(delayTime / 2);
- digitalWrite(LEDS[9], LOW);
- digitalWrite(LEDS[0], HIGH);
- for (x = 1; x <= 9; x++)
- {
- delay(delayTime);
- digitalWrite(LEDS[x - 1], LOW);
- digitalWrite(LEDS[x], HIGH);
- if(x == 5)
- {
- delayTime = delayTime + 200;
- }
- }
- if (delayTime == 650)
- {
- delay(delayTime / 2);
- digitalWrite(LEDS[x - 1], LOW);
- delay(delayTime / 2);
- digitalWrite(LEDS[x - 1], HIGH);
- delay(delayTime / 2);
- digitalWrite(LEDS[x - 1], LOW);
- delay(delayTime / 2);
- digitalWrite(LEDS[x - 1], HIGH);
- firstBatch = false;
- break;
- }
- }
- }
- void shutALlDels()
- {
- for (int i = 0; i <= 10; i++)
- {
- digitalWrite(LEDS[i], LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement