//This is a sketch for the "Simon Says" project //using a PmodDA4, LEDs, the random and //randomSeed functions, and PmodSWTs. //globals int randomValue; //random value to be received from the random function uint8_t simonSays [50]; //Simon Says (original pattern) array uint8_t iSay [50]; //User Input array int iSaySpot = 0; //Current location of the user array int buzzerPin = 4; //The pin the speaker is connected to int CS = 10; //chip select pin //global to check if we are to start in hard or easy mode, with hard mode as default boolean hardMode = true; //global buttons that correspond to the LEDs with first array member corresponding with the LED on the far right int btns[8] = {26, 27, 28, 29, 30, 31, 32, 33}; //globals defining the various needed music notes for each LED double C_4 = 261.626; double D_4 = 293.665; double E_4 = 329.628; double F_4 = 349.228; double G_4 = 391.995; double A_4 = 440.000; double B_4 = 493.883; double C_5 = 523.521; boolean finalAnsState = false; //current state of if a final answer is being submitted int finalAnsB = 3; //final answer button to be pressed int count; //how long the orignal pattern should be //including a necessary library #include void setup(){ //debugging //Serial.begin(9600); //determine hard mode or easy mode pinMode(39, INPUT); if(digitalRead(39) == LOW){ hardMode = true; } else hardMode = false; //setting up various portions, DAC that uses SPI, switches, simon and you array, etc pinMode(CS, OUTPUT); digitalWrite(CS, HIGH); SPI.begin(); // starts the SPI library object SPI.setBitOrder(MSBFIRST); // during the transfer of data, send the most significant bit first SPI.setDataMode(SPI_MODE0); // Clock starts at a LOW value and transmits data on the falling edge of the clock signal delay(5); setUpDAC(); pinMode(buzzerPin, OUTPUT); //preparing the switches on the PmodSWTs for(int i=0; i<8; i++){ pinMode(btns[i], INPUT); } //preparing the final answer button pinMode(finalAnsB, INPUT); //resetting the arrays to all zeros for(int i=0; i<50; i++){ simonSays[i]= 0; iSay[i]= 0; } delay(500); count = 1; }//end of setup void loop(){ /********************************************/ /*** Simon Input Portion of the Main Loop ***/ /********************************************/ //if we are in Hard Mode if(hardMode == true){ //resetting the arrays to all zeros for(int i=0; i<50; i++){ simonSays[i]= 0; iSay[i]= 0; } //loop to display an LED pattern of the approripate length for(int j=0; j