// Defining variables and the GPIO pins on Arduino
#define BLUE 3
#define GREEN 5
#define RED 6
#define BUTTON 2
// Defining color mode
int mode = 0;
void setup() {
pinMode(BUTTON, INPUT_PULLUP); // Set the button pin as input with internal pull-up resistor
pinMode(BLUE, OUTPUT); // Set the LED pins as output
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop() {
if (digitalRead(BUTTON) == LOW) {
mode = mode + 1;
delay(400); // Debounce delay
}
// Set the LED color based on the mode
switch (mode) {
case 0: // Off
analogWrite(BLUE, 255);
analogWrite(GREEN, 255);
analogWrite(RED, 255);
break;
case 1: // White (tuned)
analogWrite(BLUE, 0);
analogWrite(GREEN, 0);
analogWrite(RED, 0);
break;
case 2: // Red
analogWrite(BLUE, 255);
analogWrite(GREEN, 255);
analogWrite(RED, 0);
break;
case 3: // Green
analogWrite(BLUE, 255);
analogWrite(GREEN, 0);
analogWrite(RED, 255);
break;
case 4: // Blue
analogWrite(BLUE, 0);
analogWrite(GREEN, 255);
analogWrite(RED, 255);
break;
}
// Reset mode if it exceeds 4
if (mode > 4) {
mode = 0;
}
}