I have worked on a reaction game where two people will compete for who can press their button first when when the LED in the middle turns on .
If you press the button first when the LED in the middle turns on then you win! But if you press the button to early and the LED is not turned on then you losse and the other person wins. When you win, the LED on your side starts to blink very fast.
I have a problem!!!
Everything works as it should except that when you press the button too early nothing happens.
Because of this bug, you can just hold the button down before the LED in the middle is turned on and you will win automatically.
Here is the code:
void setup(){
pinMode (2,OUTPUT);
pinMode (3,INPUT);
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);
pinMode (12,INPUT);
}
void loop() {
digitalWrite( 2,LOW);
while (digitalRead(3) == LOW and digitalRead(12) ==LOW){}
if (digitalRead(3) == HIGH){
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
return;
}
else{
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
return;
}
delay(5000);
digitalWrite( 2,HIGH);
while (digitalRead(3) == LOW and digitalRead(12) ==LOW){}
if (digitalRead(3) == HIGH){
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
}
else{
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
}
}
And here is the circuit:
copy_of_copy_of_reaction_game1 (1).ino (1.46 KB)