Help with coding on game project

Hi good people of Arduino forum :) Me and my friend are new with arduino and are right now working on our first arduino project in school. Its supposed to be a pretty simple game with a led blinking a random amount of times after pressing button no 1. Then a person is supposed to press button no 2 the same amont of times as the led was blinking.

We've got two additional leds showing if he got it correct or wrong. But or problem now is the "correct led" is lighting up as soon as the player reaches the correct number of blinks. Lets say the correct number of blinks is 8. We want the player to be able to pass number 8 without the "correct led" lighting up. Perhaps the "correct led" should light up if the player has pressed 8 times, stayed there and waited 10 sec. If he reaches number 12 and stayes there for 10s the "wrong led" should light up instead.

This is what we've got so far:

http://codepad.org/qfX8EukQ

Anyone got an idea how we should code this? Thanks a lot!!

Let see...

Your program as is compile...

in your code :

int button = 13;
int button2 = 12;

//....

void setup()
{
Serial.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);

pinMode(button, INPUT); 
}

void loop()
{
  buttonState = digitalRead(button);
  buttonState2 = digitalRead(button2);

Where pinMode(button2, INPUT); ? You can not use buttonState2 = digitalRead(button2); in this case.

Techone: Where pinMode(button2, INPUT); ? You can not use buttonState2 = digitalRead(button2); in this case.

All pins default to INPUT, so the lack of calling pinMode isn't really an issue.

Sorry James C4S, did not know that...

I have great news! You get to learn about “finite state machines”!

You’ve described three states: showing the goal (button 1 clicked), collecting the user’s guess (button 2 held), displaying the results (don’t care about the buttons). Your code essentially has two states: showing the goal and “other” (collecting the user’s guess and displaying the results lumped together). You need split “other” into two separate states.

Mull over the junk above. If that isn’t enough to help, report back.