Hi,
It's my first bigger project with Arduino - it's a "reaction time test" with three LED diodes and a two buttons.
At the start - green diode is Lightining and program waits until you press the button. Than it waits some random time (2, 10 sec) and than red diode turns on and a timmer measures the time from the moment that diode turned on until you press red button.
I want to program something like program break or interupt while somebody pressed the button to early and print the "false start message" at LCD screen and do test again. The problem is that in code everything seems correct, but the "beetwen" diode just blink and even it doesnt wait this random time and starts the test:
switch (currentState) {
case IdleState:
digitalWrite(ledIdlePin, HIGH);
digitalWrite(buttonStartLedPin, HIGH);
if (digitalRead(buttonStartPin) == LOW)
{
lcd.clear();
digitalWrite(ledIdlePin, LOW);
digitalWrite(buttonStartLedPin, LOW);
digitalWrite(ledBeginPin, LOW);
lcd.print(welcome_message2);
lcd.setCursor(0,1);
lcd.print(welcome_message3);
lcd.setCursor(0,2);
lcd.print(welcome_message4);
lcd.setCursor(0,3);
lcd.print(welcome_message5);
delay(4000);
currentState = DelayState;
}
WaitTime = random(2000, 10000); //Losowanie czasu do odczekanie między zieloną a żółta diodą
break;
/*DelayState - "uzbrojenie" - zapala się żółta dioda, osoba czeka na czerwony guzik (komunikat informujący o dalszym postępowaniu) wyświetlany na ekranie komputera */
case DelayState:
{
Reakcje.reset(); //Wykorzystanie funkcji StopWatch, w celu uniknięcia kłopotliwego użycia millis() oraz micross() - źródło w pierwszej linijce kodu.
//Reset czasu przed kolejnym testem, tak aby pokazywał tylko ostatnią próbę
digitalWrite(ledBeginPin, HIGH);
lcd.clear();
lcd.print(get_ready);
lcd.setCursor(0,1);
lcd.print(get_ready1);
for (int TimeElapsed = 0; TimeElapsed <= WaitTime; TimeElapsed++)
{
if (digitalRead(buttonStopPin) == LOW)
{
lcd.clear();
lcd.print("False start");
currentState = IdleState;
break;
}
}
currentState = LightOnState;
}
'
The test works perfectly without "DelayState".
Appreciate every help