light response trainer

currently I am trying to develop a light response trainer by arduino , as a beginning I used 3 led and 3 push button ,the led must work randomly and when the ledx is flash the user press push bottonx and led off and another led on and so on ..

when uploading following code all leds continuous week glow (flash) what the problem? thanks for help :) .

int ledselect = 0; int led1 = 11; int led2 = 12; int led3 = 13; int pb1 = 4; int pb2 = 5; int pb3 = 6; void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(pb1, INPUT); pinMode(pb2, INPUT); pinMode(pb3, INPUT); } void loop() { int ledselect = random(3); switch (ledselect) { case 0: //if ledcolor equals 0 then the led1 will turn on digitalWrite(led1, HIGH); if (digitalRead(pb1),HIGH) digitalWrite(led1,LOW); break; case 1: //if ledcolor equals 1 then the led2 will turn on digitalWrite(led2, HIGH); if (digitalRead(pb2),HIGH) digitalWrite(led2,LOW); break; case 2: //if ledcolor equals 2 then the led3 will turn on digitalWrite(led3, HIGH); if (digitalRead(pb3),HIGH) digitalWrite(led3,LOW); break; }


They are on all the time because you forgot that loop repeates many hundreds of times a second.

At the start of the loop function make the first line a delay(500) so you have some time to see the results of the last random light turn on before you do the next.

But that code does nothing like you want it to do. It is hard to know where to begin because it is so far off.