// COMMENT HEADER GOES HERE
const int button1 = 8;
const int button2 = 12;
const int button3 = 13;
const int P1Led = 11;
const int P2Led = 10;
const int P3Led = 9;
const int speaker = 4;
const int resetIntb = 2;
const int continueGameb = 3;
volatile int continueGame = 0;
volatile int resetGame = 0;
int P1Stopped = 0;
int P2Stopped = 0;
int P3Stopped = 0;
// way more variables to track what is happening in the game
void setup() {
pinMode(P1Led, OUTPUT);
pinMode(P2Led, OUTPUT);
pinMode(P3Led, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(resetIntb, INPUT_PULLUP);
pinMode(continueGameb, INPUT_PULLUP);
pinMode(speaker, OUTPUT);
attachInterrupt(digitalPinToInterrupt(continueGameb), continueInt, FALLING);
attachInterrupt(digitalPinToInterrupt(resetIntb), resetInt, FALLING);
}
void loop() {
if (digitalRead(button1) == LOW && P1Stopped == 0) {
P1Stopped = 1;
buttonWasPressed(P1Led);
}
if (digitalRead(button2) == LOW && P2Stopped == 0) {
P2Stopped = 1;
buttonWasPressed(P2Led);
}
if (digitalRead(button3) == LOW && P3Stopped == 0) {
P3Stopped = 1;
buttonWasPressed(P3Led);
}
}
void buttonWasPressed(int ledToLightUp) {
while (continueGame == 0 && resetGame == 0) {
analogWrite(ledToLightUp, 255);
}
analogWrite(ledToLightUp, 5);
}
void continueInt() {
continueGame = 1;
}
void resetInt() {
analogWrite(P1Led, 0);
analogWrite(P2Led, 0);
analogWrite(P3Led, 0);
P1Stopped = 0;
P2Stopped = 0;
P3Stopped = 0;
resetGame = 1; // Set resetGame to 1 to indicate game reset
}