xenomortis
Published © GPL3+

Super Simon

Turn your Arduino into an improved version of the classic 70's toy.

BeginnerShowcase (no instructions)77
Super Simon

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Resistor 220 ohm
Resistor 220 ohm
×6
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
×6
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
5 mm LED: Red
5 mm LED: Red
×2
5 mm LED: Green
5 mm LED: Green
×2
Terminal Block, Header
Terminal Block, Header
×1
LED, Blue Green
LED, Blue Green
×2

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Basic Circuit

The high side of the pushbuttons are all the same node. Wire this to the Arduino 5V pin. Data pins 7 - 12 are connected at the anode of the LEDs, one per channel. The cathode of each LED is connected to a 220 Ohm resistor, which is connected to ground. All six resistors share a common ground. This configuration allows the button to light the led when pressed, or the LEDs can be driven directly from the digital pins on the Arduino.

Code

Simon Says

Arduino
This code will run the basic Simon game. It starts with 5 tones, advances with each successful run. After beating seven tones, it speeds up, after beating nine tones it speeds up again. Theoretically, at some point the challenge would be long enough to use all available memory, and would break the code. Good luck getting that far!
//This version of Simon Says Written by A. Wulf
//12/25/21

//************Global Variables*********************
int outVal[12];
int inVal = 0;
int toneNum;
int winLength;
int noteLength = 500;
int restLength = noteLength/5;
//*************************************************

void setup() {
 winLength = 5;     //initial length of challenge
 toneNum = 0;       //number of tones in current challenge 
outTable();         //array to hold output values
intro();            //function to flash lights and play sounds at the start of the game

}
void (*resetFunc)(void) = 0;      //software driven reset function

void loop() {
  playChallenge(toneNum);                 //play the active challenge
  compLoop(toneNum);                      //call the comparison loop
  if (toneNum >= winLength){              //if the number of tones to play is equal to the max length you win!
    youWin();
  }

}
void compLoop(int numTone){
  for(int k = 0; k <= numTone; k++){    //set comps to challenge length
    getInput();                         //wait for button value
    if(inVal != outVal[k]){             //button doesn't match current outVal
      youLose();                        //lose Con
    }    
  }
  toneNum++;                            //increase challenge length
  delay(200);                           //delay between good response and new challenge
}

void playChallenge(int toneNum){      //toneNum is 1 less than current number of tones in challenge
  dataOut();                          //set to output mode
  for(int k = 0; k <= toneNum; k++){  //cycle through outVals up to number of tones in challenge
    digitalWrite(outVal[k],HIGH);           //light LED tied to pin called in outVal[k]
    tone(A0,outVal[k]*60);            //play proper tone
    delay(noteLength);                       //hold 0.5 sec
    digitalWrite(outVal[k],LOW);
    noTone(A0);                       //LED out, no tone, hold 0.1 sec
    delay(restLength);
  }                                   //next tone value
}

int getInput(){
  dataIn();                         //set to input mode
  inVal = 0;                        //clear last input
  int timeOut = 0;                      //set timeOut to 0;
    while(inVal ==0){
      timeOut++;
      if (timeOut == 80){
        youLose();
      }
      for (int k = 7; k <=12; k++){   //read all inputs
      while (digitalRead(k) == HIGH){   //while button is pressed
        tone(A0,k*60);                  //tone is played
        if(digitalRead(k) == HIGH){       //change inVal to button pin on release
        inVal = k;
        }
      }
      delay(10);
      noTone(A0);                       //no button, no tone      
    }
   }
  return inVal;
}
void intro(){
  dataOut();
  for(int k = 7; k <= 12; k++){
    digitalWrite(k,HIGH);
    tone(A0, k*60);
    delay(50);
    digitalWrite(k,LOW);
    noTone(A0);
    delay(50);
  }
  for(int k = 12; k >= 7; k--){
    digitalWrite(k,HIGH);
    tone(A0, k*60);
    delay(50);
    digitalWrite(k,LOW);
    noTone(A0);
    delay(50);
  }
  delay(1000);
}
void outTable(){
  randomSeed(analogRead(A1));             //call seed
  for (int k = 0; k < winLength; k++){    //loop to winLength
    outVal[k] = random(7,13);               //each value is 7-12 randomized [global]
  }
}

void dataOut(){                           //sets pins 7-12 to output mode
  for (int k = 7; k<=12; k++){
    pinMode(k, OUTPUT);
  }
}

void dataIn(){                           //sets pins 7-12 to Input mode
  for (int k = 7; k<=12; k++){
    pinMode(k, INPUT);
  }
}
void youLose(){                         //lose condition
    for(int k = 0; k <= 2; k++){
      tone (A0, 400);
      delay(300);
      noTone(A0);
      delay(50);                        //plays loser song
    }
    tone(A0, 200);
    delay(1000);
    noTone(A0);
    delay(500);    
    resetFunc();                        //software reset
}

void youWin(){                                  //win condition
  for (int i = 1; i  <= 6; i++){
    for (int k = 400; k <= 800; k = k + 50){
      tone(A0, k);                              //play happy sounds
      int Pin = random(7,13);               //pick a random LED pin
      digitalWrite(Pin,HIGH);          //light random LED
      delay(75);
      digitalWrite(Pin,LOW);          //ext same LED
    }
  }
  noTone(A0);
  delay(1500);
  winLength = winLength + 1;                    //increase the max length of challenge by one
  if (winLength > 7){
    noteLength = 300;
  }
  if (winLength > 10){
    noteLength = 100;
  }
  outTable();                                   //build a new challenge array
  toneNum = 0;                                  //set current challenge length to 1
}

Credits

xenomortis
0 projects • 0 followers

Comments