So, I was trying to do a KONAMI sequence on a joystick to turn on a green led.
For those unaware, the sequence is UP UP DOWN DOWN LEFT RIGHT LEFT RIGHT.
I figured that I needed to store the sequence in an array, then compare it with the sequence of the input. But I don't know how. For now, I wrote this:
'
const int JX = A0;
const int JY = A1;
const int JB = 2;
const int RED = 4;
const int GREEN = 5;
int POS;
int Pos16;
int Pos15;
int Pos14;
int Pos13;
int Pos12;
int Pos11;
int Pos10;
int Pos9;
int Pos8;
int Pos7;
int Pos6;
int Pos5;
int Pos4;
int Pos3;
int Pos2;
int Pos1;
int Combo;
int PrevPos;
int FinPos;
int StoredPos;
void setup() {
Serial.begin(9600);
pinMode(JB, INPUT);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void loop() {
int x = analogRead(JX);
int y = analogRead(JY);
int b = digitalRead(JB);
PrevPos=POS;
if(x == 1023 && y != 0 && y != 1023){
POS = 1;
} else if(x == 0 && y != 0 && y != 1023){
POS = 2;
} else if(y == 0 && x != 0 && x != 1023){
POS = 3;
} else if(y == 1023 && x != 0 && x != 1023){
POS = 4;
} else {
POS = 0;
}
if(PrevPos != POS){
FinPos = PrevPos;
} else {
FinPos = 0;
}
Serial.println("X: " + String(x)+",\tY: " + String(y)+",\tP: " + String(b)+",\tPOS: " + String(POS)+",\tPREVPOS:"+ String(PrevPos)+",\tFINPOS:"+ String(FinPos));
delay(100);
}
How do I store the FinPos in an array?