#include <Arduino.h>
// Define pin numbers
const int pin_26 = 33; // GPIO23
const int pin_25 = 25; // GPIO25
const int pin_33 = 26; // GPIO26
const int pin_button = 27; // GPIO27
// Define pin number for the onboard LED
// const int pin_onboard_LED = 2; // Built-in LED on most ESP32 boards
// Initialize variables
int current_led = pin_25;
// Function prototypes
void switch_led();
// void toggle_onboard_led();
void setup() {
// Set pin modes
pinMode(pin_26, OUTPUT);
pinMode(pin_25, OUTPUT);
pinMode(pin_33, OUTPUT);
pinMode(pin_button, INPUT_PULLUP);
// pinMode(pin_onboard_LED, OUTPUT);
}
void loop() {
// Check if button is pressed
// toggle_onboard_led();
if (!digitalRead(pin_button)) {
// toggle_onboard_led();
// if (true) {
switch_led();
// Wait for button release
while (!digitalRead(pin_button)) {
delay(20);
}
}
delay(10); // Adjust delay as needed
}
void switch_led() {
// Turn off current LED
digitalWrite(current_led, LOW);
// Switch to the next LED
if (current_led == pin_25) {
current_led = pin_33;
} else if (current_led == pin_33) {
current_led = pin_26;
} else if (current_led == pin_26) {
current_led = pin_25;
}
// Turn on the new LED
digitalWrite(current_led, HIGH);
}
// void toggle_onboard_led() {
// // Read the current state of the LED
// int led_state = digitalRead(pin_onboard_LED);
// // Toggle the LED state
// digitalWrite(pin_onboard_LED, !led_state);
// }