Simon says tinkercad

#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 440
#define NOTE_C3 440
#define NOTE_D4 440

const int MAX_LEVEL = 3;
int sequence[MAX_LEVEL];
int your_sequence[MAX_LEVEL];                                                                         
int level=1;

int notes[]={NOTE_A4,NOTE_B4,NOTE_C3,NOTE_D4};
byte displayArray[4]={33,3,24,12};
byte gameArray[10]={1,3,1,0,2,3,0,0,1,0};
bool DA=false;
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));
  
 /* for(int pin=8;pin<=12;pin++){
  pinMode(pin,INPUT_PULLUP);
  
}*/
  pinMode(13,OUTPUT);
}
void loop()
{  
  wait4key();
  random(0,4);
  if(DA==true){
    initGameArray();
    //Serial.println("Init Array");
    DA=false;
  } 
  
}
  void initGameArray(){
  Serial.println("Init Array Function");
  for(int index=0;index<10;index++){
  gameArray[index]=random(0,4);
    }
    for(int index=0;index<10;index++){
     Serial.print(index);
     Serial.print("\t");
     Serial.print(gameArray[index]);
      Serial.print("\t");
      Serial.println(displayArray[index]);
     displaySymbol(gameArray[index]);
     delay(1000);
    }
}
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(){
  for (int i = 0; i < level; i++){
 if(digitalRead(SW1)==LOW){
  while(digitalRead(SW1)==LOW){}
  Serial.println("SW1 Pressed");
   tone(9,notes[0],20);
   displaySymbol(0);
    DA=true;
  }
  
 
  if(digitalRead(SW2)==LOW){
    while(digitalRead(SW2)==LOW){}
  Serial.println("SW2 Pressed");
   tone(9,notes[1],20);
    displaySymbol(1);
     DA=true;
  }
          if(digitalRead(SW3)==LOW){
            while(digitalRead(SW3)==LOW){}
  Serial.println("SW3 Pressed");
     tone(9,notes[2],20);
            displaySymbol(2);
             DA=true;
  }
        
  if(digitalRead(SW4)==LOW){
    while(digitalRead(SW4)==LOW){}
  Serial.println("SW4 Pressed");
    tone(9,notes[3],20);
    displaySymbol(3);
     DA=true;
  }
 }
  
  
/*  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);
      
    }
  }*/
}

void playgame()

  

Hey! I’m trying to make my code to only display one array but its keeps on initializing more arrays.

please note that this is a forum for processing

you might have more success with your question on https://www.tinkercad.com/

2 Likes