#define colorBtn 6
#define durationBtn 7
#define RED_PIN 13
#define GREEN_PIN 12
#define BLUE_PIN 11
bool colors[][3] = {
{1,1,1} , {1,0,0},{0,1,0},{0,0,1}, // wrgb
{0,1,1} , {1,1,0},{1,0,1},{0,0,0} // cymk
};
char* colorNames[] = {
"white","red","green","blue",
"cyan","yellow","megenta","black" // black is just off so do not need to toggle to black
};
int delays[] = {
1000, 800, 600, 400, 200
};
volatile int currentColor = 0;
volatile int currentDelay = 0;
unsigned long previousMillis = 0;
bool ledState = false;
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
pinMode(colorBtn, INPUT_PULLUP);
pinMode(durationBtn, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(colorBtn), changeColor, FALLING);
attachInterrupt(digitalPinToInterrupt(durationBtn), changeDuration, FALLING);
Serial.begin(9600);
Serial.println("RGB LED Blinker Initialized!");
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= delays[currentDelay]) {
previousMillis = currentMillis;
ledState = !ledState;
digitalWrite(RED_PIN, colors[currentColor][0]);
digitalWrite(GREEN_PIN, colors[currentColor][1]);
digitalWrite(BLUE_PIN, colors[currentColor][2]);
}
}
void changeColor() {
delay(50);
currentColor = (currentColor + 1) % 7;
Serial.print("Color: ");
Serial.println(colorNames[currentColor]);
}
void changeDuration() {
delay(50);
currentDelay = (currentDelay + 1) % 5;
Serial.print("Duration: ");
Serial.print(delays[currentDelay]);
Serial.println(" ms");
}