## Simon says progress

Here is the code I have so far in terms of the game: at the bottom is the tone and light (not sure how to  otherwise upload the code)

///Attempt to get simon to listen for user imput

//program Arduino to listen for user imput and compare it to what Simon says.
//The out come should trigger a lose sound, or tell Simon to say something next.

//LOSE SOUND #4*****

// void loop() {
// for (int y=200; y>80; y-=5){
// for (int x=300; x>50; x-=25){
// tone(6, y);
// delay(200); ///play with dealy “ratio”
// noTone(6);
// delay(10);
// tone(6, x);
// delay(300); ///play with dealy “ratio”
// noTone(6);
// delay(10);
// }
// }
// delay(7000);
// }
//buttons
const int switch1 = 2; //green
const int switch2 = 3;//blue
const int switch3 = 4;//red
const int switch4 = 5;//yellow

//leds
const int greenLED = 8;
const int blueLED = 9;
const int redLED = 10;
const int yellowLED = 11;

//values
const int greenVal=1; // declare values for colors for buttons
const int blueVal=2;
const int redVal=3;
const int yellowVal=4;

const int speakerPin = 12;

int counter=0;
Serial.begin(9600);
Serial.println(“Try to Guest the Contents of simonArray, try a number between 1-4!”);
int playerSays;

boolean simonDone;
int simonSays[99]={};// array that holds simon’s sequence, allows for 99 steps
//int playerSays[99]={};

int nextStep = 0; //var that counts how many steps in simon’s current sequence, used to move up in steps
int simonSpeed = 500;

void setup () {
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(speakerPin, OUTPUT);

// pinMode(switch1, INPUT);
// pinMode(switch2, INPUT);
// pinMode(switch3, INPUT);
//
// digitalWrite(switch1, HIGH); //turn on internal pull-up on siwtch1
// digitalWrite(switch2, HIGH);
// digitalWrite(switch3, HIGH);

// Serial.begin(9600);

}

void loop () {

if (simonDone ==false) { //did simon play sequence yet? bool is false by default

simonSays[nextStep] = random (1,5);

// Serial.println(“simonDone ==false”);
Serial.print(“nextStep: “); ///just to see whats happening
Serial.println(nextStep);

Serial.print(“simonSpeed: ” ); // Show how the new time feature works
Serial.println(simonSpeed); // Show how the new time feature works

Serial.print(“simonSays: “);

for(int i=0; i <=nextStep; i++) {
Serial.print(simonSays[i]); //to see count
Serial.print(“,”);
delay(simonSpeed);//controls speed that simonSays something

playToneAndLight(simonSays[i]);
}

simonSpeed=(simonSpeed-(nextStep*5)); //THis speeds up simon on each turn by formula (500-(nextStep*5)
//Change the multiplier (5 here) to make game faster or slower
//multiplier=MAJOR factor in how hard game is

simonSpeed=max(simonSpeed, 200);//max() assigns simonTime to the larger of simonTime or 200 in this case
//Sets Simon’s top speed. Also important in making game interesting yet winable

delay(500);
simonDone=true; //ok, simon done, set to true
Serial.println(” “);
}

if (simonDone==true) {

// int playerSays[99]={
// val1=1,
// val2=2,
// val3=3,
// };// array that holds player’s sequence, allows for 99 steps
// Serial.println(“playerSAYS”);
// if (simonSays==playerSays) {
// tone(6, 800, 500); ///sound for getting it right
// digitalWrite(greenLED, HIGH); //turn led on as TEST
// delay(500);
// }
//

void playToneAndLight(int color)
{

Serial.print(“inside PlayToneAndLight “);
Serial.print(” color = “);
Serial.println( color );

if(color == 1) // 1 = Red
{
digitalWrite( greenLED,HIGH);
tone(speakerPin,1000);
delay(simonSpeed);
digitalWrite( greenLED,LOW);
noTone(speakerPin);
}

if(color == 2)
{
digitalWrite( blueLED,HIGH);
tone(speakerPin,2000);
delay(simonSpeed);
digitalWrite( blueLED,LOW);
noTone(speakerPin);
}

if(color == 3)
{
digitalWrite( yellowLED,HIGH);
tone(speakerPin,3000);
delay(simonSpeed);
digitalWrite( yellowLED,LOW);
noTone(speakerPin);
}

if(color == 4)
{
digitalWrite( redLED,HIGH);
tone(speakerPin,4000);
delay(simonSpeed);
digitalWrite( redLED,LOW);
noTone(speakerPin);
}
}

// Serial.println(“simonDone ==true”);

delay(500);
Serial.println(“User got it right, add a new step and give Simon a Turn”);
simonDone=false; //user completeed successfully, give simon next turn
nextStep++; //add another step to simons sequence
}

}