user42074: I have 3 push buttons and I want to record the sequence in which they are pressed in array of size 10,i.e, I want to record 10 values for example {1,1,2,2,3,3,1,1,1,3}. I want to blink an array of 3 LED in the same pattern in which the buttons were pressed. I have two extra push buttons for putting the arduino in record and play modes respectively. If any one can suggest how I can store the values in the array I will really be very thankful. I am also facing the problem because it's very difficult to manage the bouncing of the buttons simultaneously. 

user42074: this is my code that stores the button sequence but it will be great if someone can help me blink the LED sequence an put the micro-controller in play or record mode when desired. Also this code faces some issue as some times it fails to take inputs or takes two inputs at a time:
int arr[10];
boolean previous = LOW;
unsigned long time1 = 0;
int debounce = 200;
unsigned long time2 = 0;
int index_state = 0;
void setup()
{
 for(int i = 3;i<6 ;i++)
  pinMode(i,INPUT);
 for(int n=0;n<10;n++) arr[n] = 0;//initialisition
 Serial.begin(9600);
}

void loop(){
 boolean mode = digitalRead(3) || digitalRead(4) || digitalRead(5);
 while(mode == LOW) mode = digitalRead(3) || digitalRead(4) || digitalRead(5);//wait here till one of the pushbutton goes high;
 //Serial.println("value");
 if( mode == HIGH && previous == LOW && millis() - time1 > debounce){
 //find out which one is high and store that value in array;
 if(digitalRead(3)) arr[index_state] = 3;
 else if(digitalRead(4)) arr[index_state] = 4;
 else if(digitalRead(5)) arr[index_state] = 5;
 else ;
 //print the value and the index;
 Serial.print(arr[index_state]);
 Serial.print(" Stored in index: ");
 Serial.println(index_state);
 index_state = (index_state + 1) % 10;
 //update value of time1 for button debouncing
 time1 =  millis();
}


  //update the value of previous button state
  previous = digitalRead(3) || digitalRead(4) || digitalRead(5);


  }


user31105: You can create an array like this, make it global to easy access it:
int states[10];

And the current index:
int index_state = 0;

And initialize the array (in setup):
for (int n = 0; n < 10; n++)
{
    states[n] = 0; // Unpressed
}

When a new button press should be stored:
states[index_state] = state;

And add one to the index state, if 10 is reached, start over (this means the last 10 are stored).
index_state = (index_state + 1) % 10;

And to check the states you just iterate from index_state.
Hope this helps you get going.
Note this is called a ring buffer.

42074: <p>I have 3 push buttons and I want to record the sequence in which they are pressed in array of size 10,i.e, I want to record 10 values for example {1,1,2,2,3,3,1,1,1,3}. I want to blink an array of 3 LED in the same pattern in which the buttons were pressed. I have two extra push buttons for putting the arduino in record and play modes respectively. If any one can suggest how I can store the values in the array I will really be very thankful. I am also facing the problem because it's very difficult to manage the bouncing of the buttons simultaneously. </p>
 42074: <p>this is my code that stores the button sequence but it will be great if someone can help me blink the LED sequence an put the micro-controller in play or record mode when desired. Also this code faces some issue as some times it fails to take inputs or takes two inputs at a time:</p>

<pre><code>int arr[10];
boolean previous = LOW;
unsigned long time1 = 0;
int debounce = 200;
unsigned long time2 = 0;
int index_state = 0;
void setup()
{
 for(int i = 3;i&lt;6 ;i++)
  pinMode(i,INPUT);
 for(int n=0;n&lt;10;n++) arr[n] = 0;//initialisition
 Serial.begin(9600);
}

void loop(){
 boolean mode = digitalRead(3) || digitalRead(4) || digitalRead(5);
 while(mode == LOW) mode = digitalRead(3) || digitalRead(4) || digitalRead(5);//wait here till one of the pushbutton goes high;
 //Serial.println("value");
 if( mode == HIGH &amp;&amp; previous == LOW &amp;&amp; millis() - time1 &gt; debounce){
 //find out which one is high and store that value in array;
 if(digitalRead(3)) arr[index_state] = 3;
 else if(digitalRead(4)) arr[index_state] = 4;
 else if(digitalRead(5)) arr[index_state] = 5;
 else ;
 //print the value and the index;
 Serial.print(arr[index_state]);
 Serial.print(" Stored in index: ");
 Serial.println(index_state);
 index_state = (index_state + 1) % 10;
 //update value of time1 for button debouncing
 time1 =  millis();
}


  //update the value of previous button state
  previous = digitalRead(3) || digitalRead(4) || digitalRead(5);


  }
</code></pre>
 31105: <p>You can create an array like this, make it global to easy access it:</p>

<pre><code>int states[10];
</code></pre>

<p>And the current index:</p>

<pre><code>int index_state = 0;
</code></pre>

<p>And initialize the array (in setup):</p>

<pre><code>for (int n = 0; n &lt; 10; n++)
{
    states[n] = 0; // Unpressed
}
</code></pre>

<p>When a new button press should be stored:</p>

<pre><code>states[index_state] = state;
</code></pre>

<p>And add one to the index state, if 10 is reached, start over (this means the last 10 are stored).</p>

<pre><code>index_state = (index_state + 1) % 10;
</code></pre>

<p>And to check the states you just iterate from index_state.</p>

<p>Hope this helps you get going.</p>

<p>Note this is called a ring buffer.</p>
