Hello
I am trying to make an electronic memory game... when its done it should have 5 or 6 buttons and 5 outputs.
The idea of the game is that the program shows a sequence of lights and then you have to push the buttons in the same sequence to go on to the next level...
I have tried to make it with 4 buttons and 3 outputs at the moment but it doesnt work as i would like it to...
the 4th button is a Done button, for when youre done with pushing in the sequence and then the program should check wether the sequence you pushed in is the same as the one the device showed earlier....
here is my code:
int pin2button = 2;
int pin4button = 4;
int pin6button = 6;
int outputpin3 = 3;
int outputpin5 = 5;
int outputpin7 = 7;
int array1[1] ={0};
int svararray1[1] = {};
int done = 8;
int donecheck = LOW;
int button2check = LOW;
int button4check = LOW;
int button6check = LOW;
void setup()
{
pinMode(pin2button, INPUT);
pinMode(pin4button, INPUT);
pinMode(pin6button, INPUT);
pinMode(done, INPUT);
pinMode(outputpin3, OUTPUT);
pinMode(outputpin5, OUTPUT);
pinMode(outputpin7, OUTPUT);
}
void loop()
{
start1:
digitalWrite(outputpin3, HIGH);
delay(1000);
digitalWrite(outputpin3, LOW);
delay(1000);
do
{
button2check = digitalRead(pin2button);
button4check = digitalRead(pin4button);
button6check = digitalRead(pin6button);
donecheck = digitalRead(done);
if (button2check == HIGH)
{
svararray1[1] = svararray1[1] + 0;
}
if (button4check == HIGH)
{
svararray1[1] = svararray1[1] + 1;
}
if (button4check == HIGH)
{
svararray1[1] = svararray1[1] + 2;
}
}while (donecheck == LOW);
if (svararray1[1] == array1[1])
{
goto congratulations1;
}
if (svararray1[1] != array1[1])
{
goto wrong1;
}
congratulations1:
digitalWrite(outputpin7, HIGH);
delay(100);
digitalWrite(outputpin7, LOW);
digitalWrite(outputpin5, HIGH);
delay(100);
digitalWrite(outputpin5, LOW);
digitalWrite(outputpin3, HIGH);
delay(100);
digitalWrite(outputpin3, LOW);
digitalWrite(outputpin5, HIGH);
delay(100);
digitalWrite(outputpin5, LOW);
digitalWrite(outputpin7, HIGH);
delay(100);
digitalWrite(outputpin7, LOW);
goto start2;
wrong1:
digitalWrite(outputpin3, HIGH);
delay(500);
digitalWrite(outputpin3, LOW);
delay(500);
digitalWrite(outputpin3, HIGH);
delay(500);
digitalWrite(outputpin3, LOW);
delay(500);
digitalWrite(outputpin3, HIGH);
delay(500);
digitalWrite(outputpin3, LOW);
delay(500);
goto start1;
start2:
do
{
donecheck == digitalRead(done);
}while(donecheck == LOW);
}
what i would like to know is, is there a simple or maybe another way to solve this problem?
regards
Lungefisk
edit:
What i would like it to do is store the value of the buttons pushed in an array, then when the done button is pushed it should check the array with the right answer array and if they are alike, then it should run a little sequence before movin on to the next sequence, that is a bit longer.