#include StopWatch stopwatch_button1; StopWatch stopwatch_button2; const int buttonPin_1 = 1; const int buttonPin_2 = 16; const int ledPin_1 = 3; const int ledPin_2 = 14; const int ledPin_Green = 9; int buttonState_1 = 0; // reads left button status int buttonState_2 = 0; // reads right button status bool pushedFirst_1 = false; bool pushedFirst_2 = false; bool pushedFirst_All = false; void setup() { Serial.begin(115200); // put your setup code here, to run once: pinMode(ledPin_1,OUTPUT); pinMode(ledPin_2,OUTPUT); pinMode(ledPin_Green,OUTPUT); pinMode(buttonPin_1,INPUT); pinMode(buttonPin_2,INPUT); attachInterrupt(buttonPin_1,button1PressedFirst,RISING); attachInterrupt(buttonPin_2,button2PressedFirst,RISING); } void loop() { // put your main code here, to run repeatedly: //buttonState_1 = digitalRead(buttonPin_1); //buttonState_2 = digitalRead(buttonPin_2); // if buttonA is pressed, get current val of chrono and see if buttonB is pressed // if buttonB is pressed and current chronoval2-chronoval1 <= 100ms // turn on green led // else turn on red led for buttonA // else if buttonB is pressed, get current val of chrono and see if buttonA is pressed // if buttonA is pressed and current chronoval2-chronoval1 <= 100ms // turn on green led // else turn on red led for buttonB // else no button has been pressed } void button1PressedFirst(){ // if stopwatch_button1 stopwatch not going, start stopwatch_button1 if (!stopwatch_button1.isRunning()){ stopwatch_button1.start(); } // if stopwatch_button2 is going, check chronometer if (stopwatch_button2.isRunning()){ // if chrono < 300 ms, blink green led if (stopwatch_button2.elapsed() < 300){ // blink green LED blinkLED(ledPin_Green); resetEverything(); } // else, blink button1 LED else { blinkLED(ledPin_1); resetEverything(); } } } void button2PressedFirst(){ // if stopwatch_button2 stopwatch not going, start stopwatch_button2 if (!stopwatch_button2.isRunning()){ stopwatch_button2.start(); } // if stopwatch_button1 is going, check chronometer if (stopwatch_button1.isRunning()){ // if chrono < 300 ms, blink green led if (stopwatch_button1.elapsed() < 300){ // blink green LED blinkLED(ledPin_Green); resetEverything(); } // else, blink button2 LED else { blinkLED(ledPin_2); resetEverything(); } } } void resetEverything(){ stopwatch_button1.stop(); stopwatch_button2.stop(); stopwatch_button1.reset(); stopwatch_button2.reset(); buttonState_1 = 0; buttonState_2 = 0; } void blinkLED(int ledPinNum){ digitalWrite(ledPinNum,HIGH); delay(1000); digitalWrite(ledPinNum,LOW); }