#include <EEPROM.h>
int inPin1 = 5;
int inPin2 = 6;
int inPin3 = 7;
int inpin1Val = 0;
int inpin2Val = 0;
int inpin3Val = 0;
int limit = 6;
int sequence[6] = {};
int array_count = 0;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int lastButtonState1 = 0; // previous state of the button
int lastButtonState2 = 0;
int lastButtonState3 = 0;
const int duration = 400;
const int ledPins[3] = {2,3,4};
void setup() {
Serial.begin(9600);
pinMode (ledPins[0], OUTPUT);
pinMode (ledPins[1], OUTPUT);
pinMode (ledPins[2], OUTPUT);
pinMode (inPin1, INPUT);
pinMode (inPin2, INPUT);
pinMode (inPin3, INPUT);
//const byte sequence[6] = {1,2,0,1,0,2};
int value1 = EEPROM.read(0);
if( value1 < 255){
int i;
int j;
for (i = 0; i < 6; i = i + 1) {
sequence[i] = EEPROM.read(i);
}
}
}
void loop() {
// read the pushbutton input pin:
inpin1Val = digitalRead(inPin1);
// compare the buttonState to its previous state
if (inpin1Val != lastButtonState1) {
// if the state has changed, increment the counter
if (inpin1Val == HIGH) {
sequence[array_count] = 0;
array_count++;
Serial.println(sequence[0]);
} else {
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState1 = inpin1Val;
inpin2Val = digitalRead(inPin2);
// compare the buttonState to its previous state
if (inpin2Val != lastButtonState2) {
// if the state has changed, increment the counter
if (inpin2Val == HIGH) {
sequence[array_count] = 1;
array_count++;
Serial.println(sequence[1]);
} else {
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState2 = inpin2Val;
inpin3Val = digitalRead(inPin3);
// compare the buttonState to its previous state
if (inpin3Val != lastButtonState3) {
// if the state has changed, increment the counter
if (inpin3Val == HIGH) {
sequence[array_count] = 2;
array_count++;
Serial.println(sequence[2]);
} else {
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState3 = inpin3Val;
if(array_count == 6){
int i;
int j;
for (i = 0; i < 6; i = i + 1) {
j = sequence[i];
delay (duration);
digitalWrite(ledPins[j], HIGH);
delay(duration);
digitalWrite(ledPins[j], LOW);
delay(duration);
EEPROM.write(i, j);
}
//Serial.println("I'm here at array_count 6");
array_count = 0;
}else{
int value1 = EEPROM.read(0);
//Serial.println(value1);
if( value1 < 255){
int k;
for (k = 0; k < 6; k = k + 1) {
delay (duration);
digitalWrite(ledPins[EEPROM.read(k)], HIGH);
delay(duration);
digitalWrite(ledPins[EEPROM.read(k)], LOW);
delay(duration);
}
}
//Serial.println("I'm here at else");
}
}