// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin1 = 12; // the number of the first LED pin
const int ledPin2 = 13; // the number of the second LED pin
// variables will change:
bool ledFlag1 = false; // flag for LED1
bool ledFlag2 = false; // flag for LED2
void setup() {
// initialize the LED pins as outputs:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// Set up interrupt for the button
attachInterrupt(digitalPinToInterrupt(buttonPin), buttonInterrupt, RISING);
Serial.begin(9600);
}
void loop() {
Serial.print("Flag LED1: ");
Serial.println(ledFlag1);
Serial.print("Flag LED2: ");
Serial.println(ledFlag2);
// Blink LED1 continuously
ledFlag1 = !ledFlag1;
digitalWrite(ledPin1, ledFlag1 ? HIGH : LOW);
// Blink LED2 only when both flags are true (button pressed)
if (ledFlag1 && ledFlag2) {
digitalWrite(ledPin2, HIGH);
} else {
digitalWrite(ledPin2, LOW);
}
delay(1000); // Adjust the blink rate as needed
}
void buttonInterrupt() {
// Toggle the flag for LED1 and LED2 when button is pressed
ledFlag1 = !ledFlag1;
ledFlag2 = !ledFlag2;
}