LED game

Hi guys,
I have a question about a game I’m trying to make, the purpose of the game is to press a button when the last LED of the row lights up, then the led’s go out and go on the other way. The problem with tis is, I want instant response, so when i press the button once the leds should turn around. But for some reason i have to hold the button for about 5 sec. I’m almost sure this happens because I use delays but I already tried to do it with a self made delay with millis() and that didn’t work either. Can someone help me please? I can’t find the right solution…

This is my code:

int OnOffSwitch = 12;
int OnOffLed = 11;
int Buzzer = 10;
int RedLed = 9;
int BlueLed = 8;
int GreenLed = 7;
int YellowLed = 6;
int Button2 = 3;
int Button1 = 2;
int Score = 0;
bool started;
bool Red;
bool Yellow;
bool Blue;
bool Green;
int LessDelay = 1000;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(OnOffSwitch, INPUT_PULLUP);
pinMode(OnOffLed, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(RedLed, OUTPUT);
pinMode(BlueLed, OUTPUT);
pinMode(GreenLed, OUTPUT);
pinMode(YellowLed, OUTPUT);
pinMode(Button2, INPUT_PULLUP);
pinMode(Button1, INPUT_PULLUP);
}

void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(OnOffSwitch)==LOW)
{
started = true;
Serial.println(“Het spel gaat van start!”);
digitalWrite(OnOffLed, HIGH);
digitalWrite(YellowLed, HIGH);
delay(200);
digitalWrite(GreenLed, HIGH);
delay(200);
digitalWrite(BlueLed, HIGH);
delay(200);
digitalWrite(RedLed, HIGH);
delay(200);
digitalWrite(RedLed, LOW);
delay(200);
digitalWrite(BlueLed, LOW);
delay(200);
digitalWrite(GreenLed, LOW);
delay(200);
digitalWrite(RedLed, LOW);
}
if (started == true)
{
LessDelay = LessDelay - 25;
digitalWrite(YellowLed, HIGH);
delay(LessDelay);
digitalWrite(GreenLed, HIGH);
Green = true;
if((Green == true) && (digitalRead(Button1) == LOW) or (digitalRead(Button2) == LOW))
{
Score = Score - 5;
Serial.println(Score);
}
Green = false;
delay(LessDelay);
digitalWrite(BlueLed, HIGH);
Blue = true;
if((Blue == true) && (digitalRead(Button1) == LOW) or (digitalRead(Button2) == LOW))
{
Score = Score - 5;
Serial.println(Score);
}
Blue = false;
delay(LessDelay);
digitalWrite(RedLed, HIGH);
Red = true;

if((Red == true) && (digitalRead(Button2) == LOW))
{
tone(Buzzer, 3000, 500);
delay(200);
tone(Buzzer, 4500, 300);
delay(200);
tone(Buzzer, 3500, 300);
Score = Score + 5;
Serial.println(Score);
digitalWrite(RedLed, LOW);
Red = false;
digitalWrite(BlueLed, LOW);
digitalWrite(GreenLed, LOW);
digitalWrite(YellowLed,LOW);
delay(100);
digitalWrite(RedLed, HIGH);
delay(LessDelay);
digitalWrite(BlueLed, HIGH);
Blue = true;
if((Blue == true) && (digitalRead(Button1) == LOW) or (digitalRead(Button2) == LOW))
{
Score = Score - 5;
Serial.println(Score);
}
Blue = false;
delay(LessDelay);
digitalWrite(GreenLed, HIGH);
Green = true;
if((Green == true) && (digitalRead(Button1) == LOW) or (digitalRead(Button2) == LOW))
{
Score = Score - 5;
Serial.println(Score);
}
Green = false;
delay(LessDelay);
digitalWrite(YellowLed, HIGH);
Yellow = true;
}

if((Yellow == true) && (digitalRead(Button1) == LOW))
{
tone(Buzzer, 3000, 500);
delay(200);
tone(Buzzer, 4500, 300);
delay(200);
tone(Buzzer, 3500, 300);
Score = Score + 5;
Serial.println(Score);
digitalWrite(RedLed, LOW);
digitalWrite(BlueLed, LOW);
digitalWrite(GreenLed, LOW);
digitalWrite(YellowLed, LOW);
delay(100);
digitalWrite(YellowLed, HIGH);
delay(LessDelay);
digitalWrite(GreenLed, HIGH);
Green = true;
if((Green == true) && (digitalRead(Button1) == LOW) or (digitalRead(Button2) == LOW))
{
Score = Score - 5;
Serial.println(Score);
}
Green = false;
delay(LessDelay);
digitalWrite(BlueLed, HIGH);
Blue = true;
if((Blue == true) && (digitalRead(Button1) == LOW) or (digitalRead(Button2) == LOW))
{
Score = Score - 5;
Serial.println(Score);
}
Blue = false;
delay(LessDelay);
digitalWrite(RedLed, HIGH);

}

if(LessDelay == 0)
{
digitalWrite(OnOffLed, LOW);
digitalWrite(YellowLed, LOW);
digitalWrite(GreenLed, LOW);
digitalWrite(BlueLed, LOW);
digitalWrite(RedLed, LOW);
Serial.println((String)“Je hebt een score van " + Score + " punten behaald”);

}

}
}

project-spel-2.ino (3.99 KB)

Did you read this

Installation & Troubleshooting

For problems with Arduino itself, NOT your project

Why not?

Please remember to use code tags when posting code.

Check this and see if you can create a more dynamic way of turning the led's on & off