int state1 = 0;
int state2 = 0;
int state3 = 0;
int state4 = 0;
int state5 = 0;
int state6 = 0;
int state7 = 0;
int state8 = 0;
int state9 = 0;
int state10 = 0;
int state11 = 0;
int state12 = 0;
int Switch = 7; // Push button
int R = 3; // Red pin
int G = 5; // Green pin
int B = 6; // Blue pin
int lastSwitchState = 0; // To detect press change
int State1 = 0;
int State2 = 0;
int State3 = 0;
int Switch1 = 8; // Push button
int led1 =9; // LED 1 pin
int led2 = 10; // LED 2 pin
int led3 = 11; // LED 3 pin
int lastSwitchState1 = 0;
void setup() {
pinMode(Switch1, INPUT_PULLUP); // push button
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(Switch, INPUT_PULLUP); // Use pull-up for button
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
Serial.begin(9600);
}
void loop() {
Brightness();
int currentSwitchState = digitalRead(Switch);
// Check if button pressed (LOW because of pull-up)
if (currentSwitchState == LOW && lastSwitchState == HIGH) {
// Button just pressed
if (state1 == 0) {
Serial.println("Color 1");
setColor(255, 0, 0); // 🔴 Red
allHigh(); state1 = 1; state2 = 0;
}
else if (state2 == 0) {
Serial.println("Color 2");
setColor(0, 255, 0); // 🟢 Green
allHigh(); state2 = 1; state3 = 0;
}
else if (state3 == 0) {
Serial.println("Color 3");
setColor(0, 0, 255); // 🔵 Blue
allHigh(); state3 = 1; state4 = 0;
}
else if (state4 == 0) {
Serial.println("Color 4");
setColor(255, 255, 0); // 🟡 Yellow
allHigh(); state4 = 1; state5 = 0;
}
else if (state5 == 0) {
Serial.println("Color 5");
setColor(255, 0, 255); // 🟣 Magenta
allHigh(); state5 = 1; state6 = 0;
}
else if (state6 == 0) {
Serial.println("Color 6");
setColor(0, 255, 255); // 🔵 Cyan
allHigh(); state6 = 1; state7 = 0;
}
else if (state7 == 0) {
Serial.println("Color 7");
setColor(255, 128, 0); // 🟠 Orange
allHigh(); state7 = 1; state8 = 0;
}
else if (state8 == 0) {
Serial.println("Color 8");
setColor(128, 0, 255); // 💜 Violet
allHigh(); state8 = 1; state9 = 0;
}
else if (state9 == 0) {
Serial.println("Color 9");
setColor(255, 255, 255); // ⚪ White
allHigh(); state9 = 1; state10 = 0;
}
else if (state10 == 0) {
Serial.println("Color 10");
setColor(128, 255, 0); // 💚 Lime
allHigh(); state10 = 1; state11 = 0;
}
else if (state11 == 0) {
Serial.println("Color 11");
setColor(0, 128, 255); // 💙 Sky Blue
allHigh(); state11 = 1; state12 = 0;
}
else if (state12 == 0) {
Serial.println("Color 12");
setColor(0, 0, 0); // ⚫ Off / LED Off
allHigh(); state12 = 1; state1 = 0; // loop back
}
delay(300); // debounce
}
lastSwitchState = currentSwitchState;
}
void setColor(int r, int g, int b) {
analogWrite(R, r);
analogWrite(G, g);
analogWrite(B, b);
}
// Helper to set all states high
void allHigh() {
state1 = 1; state2 = 1; state3 = 1; state4 = 1; state5 = 1;
state6 = 1; state7 = 1; state8 = 1; state9 = 1; state10 = 1;
state11 = 1; state12 = 1;
}
void Brightness() {
int currentSwitchState1 = digitalRead(Switch1);
// detect button press
if (currentSwitchState1 == LOW && lastSwitchState1 == HIGH) {
if (State1 == 0) {
Serial.println("LED 1 Brightness Up");
fadeLED(led1);
allHigh1(); State1 = 1; State2 = 0;
}
else if (State2 == 0) {
Serial.println("LED 2 Brightness Up");
fadeLED(led2);
allHigh1(); State2 = 1; State3 = 0;
}
else if (State3 == 0) {
Serial.println("LED 3 Brightness Up");
fadeLED(led3);
allHigh1(); State3 = 1; State1 = 0;
}
delay(300); // debounce
}
lastSwitchState1 = currentSwitchState1;
}
void fadeLED(int pin) {
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(pin, brightness);
delay(5); // speed of brightness increase
}
}
void allHigh1() {
State1 = 1;
State2 = 1;
State3 = 1;
}