// Pin Definitions
const int blueLedPin = 16; // Blue LED connected to GPIO 10 (sourcing mode)
const int redLedPin = 17; // Red LED connected to GPIO 11 (sinking mode)
const int buttonPin = 18; // Push button connected to GPIO 12 (active-low)
void setup() {
// Initialize pins
pinMode(blueLedPin, OUTPUT); // Set blue LED pin as output
pinMode(redLedPin, OUTPUT); // Set red LED pin as output
pinMode(buttonPin, INPUT); // Set button pin as input
// Initial state: Blue LED ON, Red LED OFF
digitalWrite(blueLedPin, HIGH); // Sourcing mode: HIGH turns on the blue LED
digitalWrite(redLedPin, HIGH); // Sinking mode: HIGH keeps the red LED off
}
void loop() {
// Read the state of the button (active-low)
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
// Button is pressed (active-low)
digitalWrite(blueLedPin, LOW); // Turn off the blue LED
digitalWrite(redLedPin, LOW); // Turn on the red LED (sinking mode)
} else {
// Button is not pressed
digitalWrite(blueLedPin, HIGH); // Turn on the blue LED
digitalWrite(redLedPin, HIGH); // Turn off the red LED
}
}