Sorry, totally forgot to post the code. As requested:
/*Simon Says game by Robert Spann*/
#include <EEPROM.h>
//Pin connected to ST_CP of 74HC595
int latchPin = 7;
//Pin connected to SH_CP of 74HC595
int clockPin = 8;
////Pin connected to DS of 74HC595
int dataPin = 6;
int switch1 = 5; //The four button input pins
int switch2 = 4;
int switch3 = 3;
int switch4 = 2;
int led1 = 9; //LED pins
int led2 = 10;
int led3 = 11;
int led4 = 12;
int turn = 0;
int speakerPin = 13;
int intro = -1;
int input1 = LOW;
int input2 = LOW;
int input3 = LOW;
int input4 = LOW;
int tenDisp;
int oneDisp;
int highTen;
int highOne;
byte dataOne; //Shift Register Stuff
byte dataTwo;
byte dataArrayOne[12];
byte dataArrayTwo[12];
int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
int inputArray[100];
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
pinMode(speakerPin, OUTPUT);
randomSeed(analogRead(0)); //Added to generate "more randomness" with the randomArray for the output function
pinMode(latchPin, OUTPUT); //Shift register output pin
dataArrayOne[0] = B11111100; //7 segment number values for shift register 1
dataArrayOne[1] = B01100000;
dataArrayOne[2] = B11011010;
dataArrayOne[3] = B11110010;
dataArrayOne[4] = B01100110;
dataArrayOne[5] = B10110110;
dataArrayOne[6] = B10111110;
dataArrayOne[7] = B11100000;
dataArrayOne[8] = B11111110;
dataArrayOne[9] = B11100110;
dataArrayOne[10] = B01101110;
dataArrayOne[11] = B11101110;
dataArrayTwo[0] = B11111100; //7 segment number values for shift register 2
dataArrayTwo[1] = B01100000;
dataArrayTwo[2] = B11011010;
dataArrayTwo[3] = B11110010;
dataArrayTwo[4] = B01100110;
dataArrayTwo[5] = B10110110;
dataArrayTwo[6] = B10111110;
dataArrayTwo[7] = B11100000;
dataArrayTwo[8] = B11111110;
dataArrayTwo[9] = B11100110;
dataArrayTwo[10] = B01101110;
dataArrayTwo[11] = B11101110;
//EEPROM.write(1, 0);
int value = EEPROM.read(1);
highScore(value);
warHymn();
delay(1000);
for (int y=0; y<=1000; y++){ //For statement to loop through the output and input functions
output();
input();
}
}
void output() { //function for generating the array to be matched by the player
scoreDisplay(turn);
for (int y=turn; y <= turn; y++){ //Limited by the turn variable
//Some serial output to follow along
Serial.print("Turn: ");
Serial.print(y + 1);
Serial.println("");
randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turn count
for (int x=0; x <= turn; x++){
Serial.print(randomArray[x]);
if (randomArray[x] == 1) { //if statements to display the stored values in the array
digitalWrite(led1, HIGH);
playTone(1915, 200); //Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led1, LOW);
delay(100);
}
if (randomArray[x] == 2) {
digitalWrite(led2, HIGH);
playTone(1519, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led2, LOW);
delay(100);
}
if (randomArray[x] == 3) {
digitalWrite(led3, HIGH);
playTone(1275, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led3, LOW);
delay(100);
}
if (randomArray[x] == 4) {
digitalWrite(led4, HIGH);
playTone(956, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led4, LOW);
delay(100);
}
}
}
}
void input() { //Function for allowing user input and checking input against the generated array
for (int x=0; x <= turn;){ //Statement controlled by turn count
input1 = digitalRead(switch1);
input2 = digitalRead(switch2);
input3 = digitalRead(switch3);
input4 = digitalRead(switch4);
if (input1 == HIGH){ //Checking for button push
digitalWrite(led1, HIGH);
playTone(1915, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led1, LOW);
inputArray[x] = 1;
delay(50);
Serial.print(" ");
Serial.print(1);
if (inputArray[x] != randomArray[x]) {
turn = -1; //Checks value input by user and checks it against
fail(); //the value in the same spot on the generated array
} //The fail function is called if it does not match
x++;
}
if (input2 == HIGH){
digitalWrite(led2, HIGH);
playTone(1519, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led2, LOW);
inputArray[x] = 2;
delay(50);
Serial.print(" ");
Serial.print(2);
if (inputArray[x] != randomArray[x]) {
turn = -1;
fail();
}
x++;
}
if (input3 == HIGH){
digitalWrite(led3, HIGH);
playTone(1275, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led3, LOW);
inputArray[x] = 3;
delay(50);
Serial.print(" ");
Serial.print(3);
if (inputArray[x] != randomArray[x]) {
turn = -1;
fail();
}
x++;
}
if (input4 == HIGH){
digitalWrite(led4, HIGH);
playTone(956, 200);//Passes tone value and duration of the tone to the playTone function
delay(200);
digitalWrite(led4, LOW);
inputArray[x] = 4;
delay(50);
Serial.print(" ");
Serial.print(4);
if (inputArray[x] != randomArray[x]) {
turn = -1;
fail();
}
int value = EEPROM.read(1);
if (turn > value) {
EEPROM.write(1, turn);
}
Serial.println();
Serial.print("High Score: ");
Serial.print(value);
Serial.println();
x++;
}
}
delay(200);
turn++; //Increments the turn count, also the last action before starting the output function over again
}
void fail() { //Function used if the player fails to match the sequence
numberOne(10);
numberTwo(11);
playTone(1432, 200);
playTone(1, 5);
playTone(1432, 200);
playTone(1700, 200);
playTone(1275, 200);
playTone(1432, 200);
playTone(1, 5);
playTone(1432, 200);
playTone(1700, 400);
for (int y=0; y<=5; y++){ //Flashes lights for failure
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
delay(200);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(200);
}
turn = -1; //Resets turn value so the game starts over without need for a reset button
}
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void highScore(int turnVal) {
int tenDisp = turnVal / 10;
int oneDisp = turnVal - (tenDisp * 10);
Serial.print(turnVal);
if (turnVal == 9) {
numberOne(1);
numberTwo(0);
}
if (turnVal == 19) {
numberOne(2);
numberTwo(0);
}
if (turnVal == 29) {
numberOne(3);
numberTwo(0);
}
if (turnVal == 39) {
numberOne(4);
numberTwo(0);
}
if (turnVal == 49) {
numberOne(5);
numberTwo(0);
}
if (turnVal < 9) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
}
if (turnVal > 9 && turnVal < 19) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
}
if (turnVal > 19 && turnVal < 29) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
}
if (turnVal > 29 && turnVal < 39) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
}
if (turnVal > 39 && turnVal < 49) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
}
}
void warHymn() { //can be changed to any tune you can figure out. This is the Texas A&M "War Hymn".
playTone(1915, 200);
playTone(1, 5);
playTone(1915, 100);
playTone(1, 5);
playTone(1915, 100);
playTone(1, 5);
playTone(1915, 200);
playTone(1, 5);
playTone(1915, 200);
playTone(1519, 400);
playTone(1915, 200);
playTone(1519, 200);
playTone(1275, 200);
playTone(1, 5);
playTone(1275, 100);
playTone(1, 5);
playTone(1275, 100);
playTone(1, 5);
playTone(1275, 200);
playTone(1519, 200);
playTone(1275, 200);
playTone(1519, 200);
playTone(1915, 600);
}
void scoreDisplay(int x) {
int tenDisp = turn / 10;
int oneDisp = turn - (tenDisp * 10);
Serial.print(turn);
if (turn == 9) {
numberOne(1);
numberTwo(0);
}
if (turn == 19) {
numberOne(2);
numberTwo(0);
}
if (turn == 29) {
numberOne(3);
numberTwo(0);
}
if (turn == 39) {
numberOne(4);
numberTwo(0);
}
if (turn == 49) {
numberOne(5);
numberTwo(0);
}
if (turn < 9) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
}
if (turn > 9 && turn < 19) {
numberOne(tenDisp);
numberTwo(oneDisp + 1);
*** NOTE: I changed the pins from previous versions because of the inclusion of the shift registers. Be sure to change your pins if you try this setup. Also, if you're wiring up a 7-segment display, the code is made to where the Q7 output for the register should be hooked up to the 'A' segment on the display (Q6 - B, Q5 - C, etc.).