// Pin definitions based on our previous wiring
const int RED_PIN = 18;
const int GREEN_PIN = 19;
const int BLUE_PIN = 21;
void setup() {
// Initialize the pins as outputs
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("RGB Basic Color Cycle Started!");
}
// Helper function to set the LED color
void displayColor(int r, int g, int b, String name) {
Serial.print("Now showing: ");
Serial.println(name);
analogWrite(RED_PIN, r);
analogWrite(GREEN_PIN, g);
analogWrite(BLUE_PIN, b);
}
void loop() {
// 1. Red (Primary)
displayColor(255, 0, 0, "Red");
delay(1000);
// 2. Green (Primary)
displayColor(0, 255, 0, "Green");
delay(1000);
// 3. Blue (Primary)
displayColor(0, 0, 255, "Blue");
delay(1000);
// 4. Yellow (Red + Green)
displayColor(255, 255, 0, "Yellow");
delay(1000);
// 5. Cyan (Green + Blue)
displayColor(0, 255, 255, "Cyan");
delay(1000);
// 6. Magenta (Red + Blue)
displayColor(255, 0, 255, "Magenta");
delay(1000);
// 7. White (Red + Green + Blue)
displayColor(255, 255, 255, "White");
delay(1000);
// 8. Black/Off
displayColor(0, 0, 0, "Off");
delay(1000);
}