I'm trying to make an arduino copy of Simon Says, the kids game where you press the colors in the same succession they appeared before, with a Joy Stick for an independent study at school. I think what I have so far will, or would, work however the array I've made gives me the "error: storage size of 'setOrder' isn't known" which makes sense because I've declared it as "int setOrder[];", but this is exactly what I want. An array which has no variables when it is created but can add variables in as the game progresses... This is what I have in my code thus far, please tell me how it looks, and how I can make an array like this. Thank You!!
int xAxis = A0;
int yAxis = A1;
int push = 6;
int blue = 9;
int yellow = 10;
int green = 11;
int red = 12;
int play = 0;
int setOrder[]; /* HERE IS THE PROBLEM */
void setup()
{
Serial.begin(9600);
pinMode(blue, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
pinMode(push, INPUT);
digitalWrite(push, HIGH);
}
void loop()
{
if(!digitalRead(push)){
play = 1;
Serial.println("start!");
}
if(play = 1){
for(int i = 0; i<=sizeof(setOrder); i++){
setOrder[i] = random(1, 4);
for(int j = 0; j<=sizeof(setOrder); j++){
int k = setOrder[j];
if(k=1){
digitalWrite(blue, HIGH); delay(750); digitalWrite(blue, LOW);
}
if(k=2){
digitalWrite(yellow, HIGH); delay(750); digitalWrite(yellow, LOW);
}
if(k=3){
digitalWrite(green, HIGH); delay(750); digitalWrite(green, LOW);
}
if(k=4){
digitalWrite(red, HIGH); delay(750); digitalWrite(red, LOW);
}
}
int playback[sizeof(setOrder)];
for(int l = 0; l<=sizeof(playback); l++){
//player presses RIGHT green led
if(analogRead(xAxis) > 600){
playback[l] = 4;
if(playback[l] == setOrder[l]){
digitalWrite(green, HIGH);
}
else{
digitalWrite(green, HIGH); digitalWrite(blue, HIGH); digitalWrite(yellow, HIGH); digitalWrite(red, HIGH);
play = 0;
break;
}
}
//player presses LEFT yellow led
if(analogRead(xAxis) < 400){
playback[l] = 2;
if(playback[l] == setOrder[l]){
digitalWrite(yellow, HIGH);
}
else{
digitalWrite(green, HIGH); digitalWrite(blue, HIGH); digitalWrite(yellow, HIGH); digitalWrite(red, HIGH);
play = 0;
break;
}
}
//player presses DOWN blue led
if(analogRead(yAxis) > 600){
playback[l] = 1;
if(playback[l] == setOrder[l]){
digitalWrite(blue, HIGH);
}
else{
digitalWrite(green, HIGH); digitalWrite(blue, HIGH); digitalWrite(yellow, HIGH); digitalWrite(red, HIGH);
play = 0;
break;
}
}
//player presses UP red led
if(analogRead(yAxis) < 400){
playback[l] = 3;
if(playback[l] == setOrder[l]){
digitalWrite(red, HIGH);
}
else{
digitalWrite(green, HIGH); digitalWrite(blue, HIGH); digitalWrite(yellow, HIGH); digitalWrite(red, HIGH);
play = 0;
break;
}
}
}
}
}
}
Also I'm not sure if I'm using the "break();" method correctly, if someone could tell me that'd be great! thanks again.