Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Wheel of Fortune
- //Version : 01
- //MJ - 14-01-2020
- // Define Pins
- int delayTime = 50;
- int LEDS[10];
- int buttonpin = 13;
- bool startRolling = false;
- 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;
- //digitalWrite(LEDS[9], HIGH);
- //Serial.println(millis()/500);
- //delay(500);
- delay(delayTime / 2);
- //digitalWrite(LEDS[9], HIGH);
- if (digitalRead(buttonpin) == LOW)
- {
- startRolling = true;
- }
- /*else
- {
- shutALlDels();
- startRolling = false;
- //Serial.print(LEDS[y]);
- //Serial.println();
- }*/
- if (startRolling)
- {
- rollLoop();
- startRolling = false;
- }
- }
- 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 rollLoop()
- {
- //get random number 0 to 9 and set starting led for actually random result
- int lastDel = 0;
- while (delayTime <= 700)
- {
- 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 (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);
- delay(2500);
- }
- delayTime = delayTime + 200;
- }
- }
- void shutALlDels()//for some odd reasons using for loop here create strange behavior - last leds is half unpowered
- {
- //need to fix with for loop
- for (int i = 0; i <= 10; i++)
- {
- digitalWrite(LEDS[i], LOW);
- }
- /*digitalWrite(LEDS[0], LOW);
- digitalWrite(LEDS[1], LOW);
- digitalWrite(LEDS[2], LOW);
- digitalWrite(LEDS[3], LOW);
- digitalWrite(LEDS[4], LOW);
- digitalWrite(LEDS[5], LOW);
- digitalWrite(LEDS[6], LOW);
- digitalWrite(LEDS[7], LOW);
- digitalWrite(LEDS[8], LOW);
- digitalWrite(LEDS[9], LOW);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement