#define colorBtn 6
#define durationBtn 7
#define r_pin 13
#define g_pin 12
#define b_pin 11
bool colors[][3] = {
{1,1,1}, {1,0,0},{0,1,0},{0,0,1},
{0,1,1} , {1,1,0},{1,0,1},{0,0,0}
};
char* colorNames[] = {
"white", "red", "green", "blue",
"cyan", "yellow", "magenta", "black"
};
int delays[] = {
1000, 800, 600, 400, 200
};
int colorIdx = 0;
int delayIdx = 0;
bool lastColorBtnState = HIGH;
bool lastDurationBtnState = HIGH;
unsigned long lastBlinkTime = 0;
bool ledOn = false;
void setup() {
pinMode(colorBtn, INPUT_PULLUP);
pinMode(durationBtn, INPUT_PULLUP);
pinMode(r_pin, OUTPUT);
pinMode(g_pin, OUTPUT);
pinMode(b_pin, OUTPUT);
}
void loop() {
bool colorBtnState = digitalRead(colorBtn);
if (colorBtnState == LOW && lastColorBtnState == HIGH) {
colorIdx = (colorIdx + 1) % 7;
delay(50);
}
lastColorBtnState = colorBtnState;
bool durationBtnState = digitalRead(durationBtn);
if (durationBtnState == LOW && lastDurationBtnState == HIGH) {
delayIdx = (delayIdx + 1) % 5;
delay(50);
}
lastDurationBtnState = durationBtnState;
unsigned long currTime = millis();
if (currTime - lastBlinkTime >= delays[delayIdx]) {
lastBlinkTime = currTime;
ledOn = !ledOn;
if (ledOn) {
digitalWrite(r_pin, colors[colorIdx][0]);
digitalWrite(g_pin, colors[colorIdx][1]);
digitalWrite(b_pin, colors[colorIdx][2]);
} else {
digitalWrite(r_pin, LOW);
digitalWrite(g_pin, LOW);
digitalWrite(b_pin, LOW);
}
}
}