So this is what my team has come up with. the directions are "You will be creating a game that can be played by one person. The game is similar to Simon Says. You will need: 1.Two pushbuttons2.Two LEDs that are different colors3.All the associated items to have the LED and pushbuttons to work The LEDs and the pushbuttons should be physically located so that one pushbutton is associated with one button and the other pushbutton is associated with the other LED.The microcontroller is going to play a sequence of lights starting with a length of one and then continue up to 10 long. For each round, the sequence of lights will be flashed. The light should be on for 1 second and no lights on for 0.5 seconds for each flash.Then the player will need to duplicate the sequence on the pushbuttons. Each time the player pushes a button the corresponding LED should light up. If the sequence is correct, wait for 2 seconds with both lights off before starting the next round. If the player completes all 10 rounds correctly, have both lights flash at a rate of 2 Hz. This will occur until one of the buttons is pressed, then the game will start over. If the player is incorrect for the sequence, the lights should alternate at a rate of 1 Hz and should continue flashing until one of the buttons is pushed. Then the game will start over."
We have been struggling for several days and still don't understand what went wrong. It was supposed to start with a click of a random button, then the lights will start flashing for five times or continuously first. then when level 1 will start and go from there. It didn't work after we apply the codes for the levels. It was working before tho.
const int buttonPin1 = 10;
const int buttonPin2 = 11;
const int redledPin = 7;
const int blueledPin = 6;
int buttonState = 0;
const int MAX_LEVEL = 10;
int sequence[MAX_LEVEL];
int your_sequence[MAX_LEVEL];
int level = 1;
void setup()
{
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
}
void loop()
{
{
while ( digitalRead(10) == LOW || digitalRead(11) == LOW)
for (int i=0; i<5; i++)
{
digitalWrite(7, HIGH);
delay(100);
digitalWrite(7, LOW);
delay(100);
digitalWrite(6, HIGH);
delay(100);
digitalWrite(6, LOW);
delay(100);
}
}
if (level == 1)
generate_sequence();
if (digitalRead(10) == LOW || level !=1) {
show_sequence();
get_sequence();
}
}
void show_sequence()
{ digitalWrite(7,LOW);
digitalWrite(6,LOW);
for (int i = 0; i < level; i++)
{ digitalWrite(sequence[i], HIGH);
delay(1000);
digitalWrite(sequence[i],LOW);
delay(500);
}
}
void get_sequence()
{
int flag = 0;
for (int i = 0; i < level; i++)
{
flag = 0;
while(flag == 0)
{
if (digitalRead(10) == LOW)
{
digitalWrite(7,HIGH);
your_sequence[i] = 7;
flag = 1;
delay(2000);
if (your_sequence[i] != sequence[i])
{
wrong_sequence();
return;
}
digitalWrite(7,LOW);
}
if (digitalRead(11) == LOW)
{
digitalWrite(6,HIGH);
your_sequence[i] = 6;
flag = 1;
delay(2000);
if (your_sequence[i] != sequence[i])
{
wrong_sequence();
return;
}
digitalWrite(6,LOW); }
}
}
right_sequence();
}
void generate_sequence()
{
randomSeed(millis());
for (int i = 0; i < MAX_LEVEL; i++)
{
sequence[i] = random(7,6); }
}
void wrong_sequence()
{
for (int i = 0; i < 10; i++)
{
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
digitalWrite(6,HIGH);
delay(500);
digitalWrite(6,LOW);
delay(500); }
level = 1;
}
void right_sequence()
{
digitalWrite(7,HIGH);
delay(250);
digitalWrite(7,LOW);
delay(250);
digitalWrite(6,HIGH);
delay(250);
digitalWrite(6,LOW);
delay(250);
if (level < MAX_LEVEL);
level++;
}