Hello! please could someone tell me what is causing this?Here is my code
#define SW1 8
#define SW2 11
#define SW3 10
#define SW4 12
#define aSeg 2
#define bSeg 3
#define cSeg 4
#define dSeg 5
#define eSeg 6
#define fSeg 7
#define gSeg 13
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C3 131
#define NOTE_D4 294
int level = 0;
int score = 0;
int symbol = -1;
int index = 0;
int winner = 10;
int notes[] = {NOTE_A4, NOTE_B4, NOTE_C3, NOTE_D4};
byte displayArray[4] = {33, 3, 24, 12};
byte gameArray[10] = {};
bool DA = false;
byte floatingPin = 1;
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(10, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
randomSeed(analogRead(0));
initGameArray();
DA = false;
/* for(int pin=8;pin<=12;pin++){
pinMode(pin,INPUT_PULLUP);
}*/
pinMode(13, OUTPUT);
}
void loop()
{
wait4key();
random(0, 4);
if (DA == true) {
}
DA = false;
if (level > winner) {
Serial.print("You Win!");
level = 0;
randomSeed(analogRead(floatingPin));
gameArray[index] = (random(0, 4));
}
}
void initGameArray() {
DA = false;
randomSeed(analogRead(floatingPin));
// Serial.print("Simon says game,press the switch the 7 segment display is indicating to Start!");
Serial.println("Follow the sequence");
// gameArray[index]=random(0,4);
// }
for (index = 0; index < winner; index++) {
gameArray[index] = (random(0, 4));
Serial.print(" ");
Serial.print(gameArray[index]);
displaySymbol(gameArray[index]);
}
Serial.print("\n");
}
void displaySymbol(byte sym) {
digitalWrite(aSeg, bitRead(displayArray[sym], 0));
digitalWrite(bSeg, bitRead(displayArray[sym], 1));
digitalWrite(cSeg, bitRead(displayArray[sym], 2));
digitalWrite(dSeg, bitRead(displayArray[sym], 3));
digitalWrite(eSeg, bitRead(displayArray[sym], 4));
digitalWrite(fSeg, bitRead(displayArray[sym], 5));
digitalWrite(gSeg, bitRead(displayArray[sym], 6));
}
void wait4key() {
if (digitalRead(SW1) == LOW) {
while (digitalRead(SW1) == LOW) {}
tone(9, notes[0], 20);
//displaySymbol(0);
//DA=true;
symbol = 0;
if (symbol == gameArray[index - 1]) {
level++;
} else {
Serial.print("You LOSE,Press the correct button to restart the game");
level = 0;
Serial.print("\n");
return;
}
for (index = 0; index < level; index++) {
Serial.print(" ");
Serial.print(gameArray[index]);
displaySymbol(gameArray[index]);
}
Serial.print("\n");
}
if (digitalRead(SW2) == LOW) {
while (digitalRead(SW2) == LOW) {}
tone(9, notes[1], 20);
//displaySymbol(1);
//DA=true;
symbol = 1;
if (symbol == gameArray[index - 1]) {
level++;
} else {
Serial.print("You LOSE,Press the right button to restart the game");
level = 0;
Serial.print("\n");
return;
}
for (index = 0; index < level; index++) {
Serial.print(" ");
Serial.print(gameArray[index]);
displaySymbol(gameArray[index]);
}
Serial.print("\n");
}
if (digitalRead(SW3) == LOW) {
while (digitalRead(SW3) == LOW) {}
tone(9, notes[2], 20);
// displaySymbol(2);
// DA=true;
symbol = 2;
if (symbol == gameArray[index - 1]) {
level++;
} else {
Serial.print("You LOSE,Press the right button to restart the game");
level = 0;
Serial.print("\n");
return;
}
for (index = 0; index < level; index++) {
Serial.print(" ");
Serial.print(gameArray[index]);
displaySymbol(gameArray[index]);
}
Serial.print("\n");
}
if (digitalRead(SW4) == LOW) {
while (digitalRead(SW4) == LOW) {}
tone(9, notes[3], 20);
// displaySymbol(3);
//DA=true;
symbol = 3;
if (symbol == gameArray[index - 1]) {
level++;
} else {
Serial.print("You LOSE,Press the right button to restart the game");
level = 0;
Serial.print("\n");
return;
}
for (index = 0; index < level; index++) {
Serial.print(" ");
Serial.print(gameArray[index]);
displaySymbol(gameArray[index]);
}
Serial.print("\n");
}
/* for(int pin=8;pin<=12;pin++){
if(digitalRead(pin)==LOW){
while(digitalRead(pin)==LOW){}
Serial.print("Button Pressed=");
Serial.println(pin-8);
tone(11,notes[pin-8],20);
//displaySymbol(pin-8);
}
}*/
}