/*Outreach splicing game*/ // Constants - their value won't change. // They're used here to set pin numbers: const int buttonPin = 0; // the number of the pushbutton pin // Variables - their values will change: int gameCounter = 0; // variable for checking how many times the button has been pressed int gSpeed = 800; // initial game speed - time in milliseconds each led is turned on int prevButtonState = LOW; // Variable to ensure two button presses are NOT recorded if the button is simply held down int currentButtonState = LOW; // Variable to ensure two button presses are NOT recorded if the button is simply held down int firstPress = 0; // Variable to record which LED was active when the button was pressed the first time int secondPress = 0; // Variable to record which LED was active when the button was pressed the second time bool buttonPressed = false; // Variable to tell you when to end for loops // the setup function runs once when you press reset or power the board void setup() { // Initialize all digital pins as output pins. for(int i = 1; i<14; i++){ pinMode(i, OUTPUT); } // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } //used in loop for logic void levelUp(int press1, int press2){ if (press1 == 4 && press2 == 9){ //Level PASSED!! Level up! //update gSpeed value gSpeed = gSpeed/2; } else{ //FAIL //digitalWrite(13, HIGH); //delay(4000); //10 second delay //digitalWrite(13, LOW); } //Flash winning values for(int j = 0; j<6; j++){ digitalWrite(press1, HIGH); delay(500); //0.5 seconds on digitalWrite(press1, LOW); digitalWrite(press2, HIGH); delay(500); //0.5 seconds on digitalWrite(press2, LOW); } } //handle what happens when button is pressed bool gameLogic(int i){ bool output = false; //get current push button state currentButtonState = ! digitalRead(buttonPin); if(currentButtonState == HIGH){//button is pressed //check to see if button is just being held down if(prevButtonState == HIGH){ //pass. Button is being held down. 'Previous button state' remains high } else{ //New button press //increment game counter gameCounter ++; //test to see if time to end game if(gameCounter == 2){ //end game //set game counter to 0 gameCounter = 0; //set second press position identifier secondPress = i; //turn off most recent led digitalWrite(i, LOW); //display result and continue/level up if(firstPress0; i--){ /* turn the LED on (HIGH is the voltage level) */ digitalWrite(i, HIGH); // wait for designated time for(int k = 0; k