// Pin definitions
const int buttonPin = 2; // Button connected to pin 2
const int redLEDPin = 3; // Red LED connected to pin 3
const int greenLEDPin = 4; // Green LED connected to pin 4
const int blueLEDPin = 5; // Blue LED connected to pin 5
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// Read the button state
int buttonState = digitalRead(buttonPin);
// Control LEDs based on the button state
if (buttonState == HIGH) {
digitalWrite(redLEDPin, HIGH); // Turn on red LED
digitalWrite(greenLEDPin, LOW); // Turn off green LED
digitalWrite(blueLEDPin, LOW); // Turn off blue LED
} else {
digitalWrite(redLEDPin, LOW); // Turn off red LED
digitalWrite(greenLEDPin, HIGH); // Turn on green LED
digitalWrite(blueLEDPin, HIGH); // Turn on blue LED
}
}