really need help :(

Hii, noob here
i need to make a simon says game with arduino.
Here my source code :

long randNumber;
long Read;
int timer = 1000;
int i, x;
int buttonState ;
int buttons;

void setup() {
  for (int thisPin = 2; thisPin < 8; thisPin++){
   pinMode(thisPin, OUTPUT);      
  for (int buttons = 8; buttons<12; buttons++){
    pinMode(buttons, INPUT);
   //digitalWrite(buttons, HIGH);

void loop() { 
      for (i=0; i<6;i++){
        randNumber = random(3,6);
      digitalWrite(randNumber, HIGH);   
      // turn the pin off:
      digitalWrite(randNumber, LOW);  

     /* Serial.println("mati");
     digitalWrite(randNumber, LOW);
     delay (5000);

Wanna ask, how to put a light that have been HIGH to stack, so that i can save which light has been on?
i need a button to reset the game, how can i programme it?
and how can i sync a button to a light that has been on?

best thanks.

Moderator edit: CODE TAGS - seriously, why is it so hard to understand?
sp. “want to”, unless you want to sound like a two year-old.

Read a bit about saving things to an array, ex. Arrays


Hi -

You need a state machine.
Its basically an event controller that keeps an eye on the elapsed time and compares it to a set time.

The code is simple, but the theory behind is not so simple to understand.
I've been through this exact same just hours ago and ran over the code from Jasmine2051 :

  State Machine.
  This is a piece of code that constitutes a state machine.
  It is used to start an event, then keeping an eye on that event to see if its time slot has elapsed.
  The state machine is what you need to avoid using the "sleep-mode" function delay().
  Note that the code relies on global variables to store the STATE of the events.
  If you try calling the event functions with these variables as parameters, it wont work, as the
  parameters then will be considered local variables in the scope of the functions.
  In this code two events controls two blinking LEDs with individual blink intervals, using an event function for each LED.

  The code is written and explained by :
  In this youtube video : 
  Modified 29-03-15 by Anders53

// Constants defines pin numbers
const int greenLedPin = 11;           // the number of the green LED pin
const int redLedPin = 12;             // the number of the green LED pin

// Variables will change
int greenLedState = HIGH;             // ledState for green LED
int redLedState = HIGH;               // ledState for red LED
long previousMillisRed = 0;           // last time Red LED was updated
long previousMillisGreen = 0;         // last time Green LED was updated

// Must be long integers to prevent overflow
long greenLedInterval = 1100;         // interval to blink green LED (milliseconds)
long redLedInterval = 1110;           // interval to blink red LED (milliseconds)
unsigned long currentMillis = 0;      // Current time (milliseconds)

void setup()
{  // Set the pins to output mode
  pinMode(greenLedPin, OUTPUT);
  pinMode(redLedPin, OUTPUT);
  digitalWrite(redLedPin, redLedState);
  digitalWrite(greenLedPin, greenLedState);

void loop()
  currentMillis = millis(); // Capture the current time

void manageRedLed()  // function : check if it's time to change state of the Red LED yet
  if (currentMillis - previousMillisRed > redLedInterval) // state change condition
    previousMillisRed = currentMillis;  //store the time of this state change
    // next 2 lines is the event controlled
    redLedState = (redLedState == HIGH) ? LOW : HIGH;
    digitalWrite(redLedPin, redLedState);

void manageGreenLed() // function : check if it's time to change state of the green LED yet
  if (currentMillis - previousMillisGreen > greenLedInterval) // state change condition
    previousMillisGreen = currentMillis; //store the time of this state change
    // next 2 lines is the event controlled
    greenLedState = (greenLedState == HIGH) ? LOW : HIGH;
    digitalWrite(greenLedPin, greenLedState);