[simon says]

//Button Pins

const int redButt = 11; // declare pins for buttons
const int yellButt = 10;
const int blueButt = 9;
const int greenButt = 8;

//LED Pins
const int redLED = 2; // declare pins for LED’s
const int yellLED = 3;
const int blueLED = 4;
const int greenLED = 5;
// Color Code we Use for R,Y,B,G and 1,2,3,4 repectfully
const int redValue = 1; // declare values for colors for buttons
const int yellValue = 2;
const int blueValue = 3;
const int greenValue = 4;

const int speakerPin = 7 ; //declare your speaker pin

boolean simonDone;
int simonSays[99] ={
};
int nextStep = 0 ;
int userStep=0;

int simonSpeed = 300;
void setup()
{
pinMode(redLED, OUTPUT); //Set Pin Mode
pinMode(yellLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(speakerPin, OUTPUT); // set speaker to output
Serial.begin(9600);
randomSeed(analogRead(0));
}

void loop ()
{
if (simonDone == false)
{
simonSays[nextStep] = random(1,5) ;

// Serial.print(“nextStep: ” );
// 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]);
Serial.print(” , “);
delay(simonSpeed); // controls speed that simonSays something

playToneAndLight(simonSays[i]);

}

simonSpeed= (simonSpeed – (nextStep*5)); // This seeds up Simon on each turn by forumla (500-(nextStep*5).
// Change the multiplier (5 in this case) to make game faster or slower
// The multiplier is MAJOR factor in how hard the game is.
// This sets Simon’s TOP SPEED. Also important in making game interesting yet winable.
simonSpeed = max(simonSpeed, 200); //this maxes out simon speed at 200 ms
simonDone = true;
//Serial.println(” “);
}
if (simonDone == true)
{

if(digitalRead (redButt)==LOW) {
playToneAndLight (1);
userCheck(1);
}

else if(digitalRead (yellButt)==LOW){
playToneAndLight (2);
userCheck(2);
}

else if(digitalRead (blueButt) ==LOW) {
playToneAndLight (3);
userCheck(3);
}

else if( digitalRead(greenButt) == LOW) {
playToneAndLight(4);
userCheck(4);
}

 
// nothing happening here yet
// delay(1000);

// Serial.println(“User got it right, add a new step and give Simon a Turn”);

// // user completed successfully, give simon the next turn
// // add one more step to simon’s sequence
}
}
void userCheck (int x) {
Serial.println(“–starting values–“);
Serial.print(“value checking against “);
Serial.print(simonSays[userStep]);
Serial.print(” “);
Serial.print(“value user “);
Serial.println(x);
Serial.println(” user “);
Serial.println(userStep);
Serial.println(” simon “);
Serial.println(nextStep);
Serial.println(“—-“);

if(x==simonSays[userStep]) {

Serial.println(“User right”);
if(userStep == nextStep) {
simonDone = false;
nextStep++;
userStep=0;
}
else {
userStep++;
}
}
else {
tone(7, random(100,3000), 100);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
delay(100);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(100);
tone(7, random(100,3000), 100);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
delay(100);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(100);
tone(7, random(100,3000), 100);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
delay(100);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(100);
nextStep=0;
userStep=0;
simonDone = false;
Serial.println(“Failure”);
}
Serial.println(“–outputnext–“);
Serial.println(userStep);
Serial.println(nextStep);
Serial.println(“—-“);
}