Hi all arduino masters.
I am trying to do an electronic whack a mole with six leds and six push buttons. The led will light up randomly, and the push button will switch off the led on pressing. I have been able to switch it off with the code below, but then the whole sketch just stop, other led does not light up again. Please advise how to fix this problem.
All help and advice rendered very much appreciated.
//Input and Output Initialized
int LED1 = 8; // initialise LED
int LED2 = 9;
int LED3 = 10;
int LED4 = 11;
int LED5 = 12;
int LED6 = 13;
int BTN1 = A0; // initialize push button
int BTN2 = A1;
int BTN3 = A2;
int BTN4 = A3;
int BTN5 = A4;
int BTN6 = A5;
// a variable to hold a random number
long randomNumber;
void setup() {
// start serial communication
Serial.begin(9600);
delay(150);
// send at start messages to the serial monitor
Serial.println("Start a new sequence of random number");
// set LED pins as output
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
pinMode (LED5, OUTPUT);
pinMode (LED6, OUTPUT);
// set BTN pins as input
pinMode (BTN1, INPUT);
pinMode (BTN2, INPUT);
pinMode (BTN3, INPUT);
pinMode (BTN4, INPUT);
pinMode (BTN5, INPUT);
pinMode (BTN6, INPUT);
}//close setup
void loop() {
//assign a random number to our variable
randomNumber = random(8,14);
//print the output to the serial monitor window
Serial.print("The Random Number is = ");
Serial.println(randomNumber);
//turn on a "Random LED"
digitalWrite(randomNumber, HIGH);
//delay to see the LED light up
delay(1000);
//turn LED off
digitalWrite(randomNumber, LOW);
}