Hi, I am looking to make a lucky wheel with Arduino Uno that consists of 4 LED which is activated by a button. Something similar to this: Demonstration: Arduino Lucky Wheel w/Nano, LEDs, Buzzer & 3D-Printed Wheel - YouTube
However, I am having trouble with the code.
What it does now: Starts by pushing button, takes a small break after the round is finished and then it starts a new round on itself.
If anyone have any suggestions, I would really appreciate it. Here is the current code:
// Create a global variable to hold the state of the switch. This variable is
// persistent throughout the program. Whenever you refer to switchState, you’re
// talking about the number it holds
int switchstate = 0;
int randomNumber = 0;
void setup() {
// declare the LED pins as outputs
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
// declare the switch pin as an input
pinMode(7, INPUT);
}
void loop() {
// read the value of the switch
// digitalRead() checks to see if there is voltage on the pin or not
switchstate = digitalRead(7);
int myLeds[] = {3, 4, 5, 6};
// if the button is not pressed turn on the green LED and off the red LEDs
if (switchstate == HIGH) {
for(int thisLed=0; thisLed<=1; thisLed++){
delay(100);
digitalWrite(3, HIGH); // turn the red LED on pin 4 off
delay(500);
digitalWrite(4, HIGH); // turn the red LED on pin 5 off
delay(500);
digitalWrite(5, HIGH); // turn the green LED on pin 3 off
delay(500);
digitalWrite(6, HIGH); // turn the red LED on pin 4 off
delay(500);
/* for(int thisLed=0; thisLed<=3; thisLed++){*/
digitalWrite(3, LOW); // turn the red LED on pin 4 off
delay(500);
digitalWrite(4, LOW); // turn the red LED on pin 5 off
delay(500);
digitalWrite(5, LOW); // turn the green LED on pin 3 off
delay(500);
digitalWrite(6, LOW); // turn the red LED on pin 4 off
delay(500);
}
randomNumber = random(0,3);
digitalWrite(myLeds[randomNumber],HIGH);
Serial.println("det randome nr er: ");
Serial.println(randomNumber);
/*delay(100);
digitalWrite(3, HIGH); // turn the red LED on pin 4 off
delay(500);
digitalWrite(4, HIGH); // turn the red LED on pin 5 off
delay(500);
digitalWrite(5, HIGH); // turn the green LED on pin 3 off
delay(500);
digitalWrite(6, HIGH); // turn the red LED on pin 4 off
delay(500); */
/* for(int thisLed=0; thisLed<=3; thisLed++){*/
/* randomNumber = random(2,7);
digitalWrite(randomNumber,HIGH);
Serial.println("det randome nr er: ");
Serial.println(randomNumber);*/
//}
}
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed) turn off the green LED and
// blink alternatively the red LEDs
else {
digitalWrite(3, LOW); // turn the red LED on pin 4 off
digitalWrite(4, LOW); // turn the red LED on pin 5 on
digitalWrite(5, LOW); // turn the red LED on pin 5 on
// wait for a quarter second before changing the light
// delay(250);
digitalWrite(6, LOW); // turn the red LED on pin 4 on
// wait for a quarter second before changing the light
//delay(250);
}
}