volatile bool Mode_one = false;
volatile bool Mode_two = false;
bool lastModeOne = false;
bool lastModeTwo = false;
void IRAM_ATTR Mode_first(){
Mode_one = true;
}
void IRAM_ATTR Mode_second(){
Mode_two = true;
}
void setup() {
Serial.begin(9600);
pinMode(33, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(33), Mode_first, FALLING);
pinMode(32, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(32), Mode_second, FALLING);
pinMode(27, OUTPUT);
}
void loop() {
// Handle Mode_one toggle
if(Mode_one) {
Mode_one = false;
lastModeOne = !lastModeOne;
if(lastModeOne) {
lastModeTwo = false; // Disable other mode
Serial.println("Mode 1 ON");
} else {
Serial.println("Mode 1 OFF");
}
}
// Handle Mode_two toggle
if(Mode_two) {
Mode_two = false;
lastModeTwo = !lastModeTwo;
if(lastModeTwo) {
lastModeOne = false; // Disable other mode
Serial.println("Mode 2 ON");
} else {
Serial.println("Mode 2 OFF");
}
}
// Execute based on active mode
if(lastModeOne) {
analogWrite(27, 191);
}
else if(lastModeTwo) {
analogWrite(27, 64);
}
else {
digitalWrite(27, LOW);
}
}LED 27 PIN OUTPUT
BUTTON 33 PIN INPUT