I am designing simple "Simon Says game" using Arduino. Simon says is a game in which a LED pattern is played and user has to mimic the pattern. There are 10 Rounds. First Round = 1 led, second round = 2 leds and so on. When the first round is played, one led blinks and player has to press the corresponding button. Then if it presses the right button, next round plays in which two LEDs glow and player has to press 2 buttons in sequence. I am having problem in detecting the button press in a loop for more than 1 round. Here is snippet of the code:
void loop() {
for (int i = 1; i <= ROUNDS; i++)
{
digitalWriteGeneric(i);
bool wait = 1;
int expected = Sequence[i - 1];
while (wait)
{
int value = digitalReadGeneric();
if (expected == value)
{
Serial.print("Right");
wait = 0;
break;
}
}
}
}
int digitalReadGeneric()
{
for (int i = 0; i < NUM_LIGHTS; i++)
{
Readings[i] = digitalRead(buttonPin[i]);
if (Readings[i] == 1)
{
return i;
}
}
}
Here, ROUNDS = 10 digitalwritegeneric is working fine, it plays the pattern for corresponding pattern. For round more than one how can i detect button press in sequence?. Kindly tell, what I am doing wrong.