// RGB LED cycle through the colors of the rainbow
const int redPin = 15; // GPIO 15 is connected to the red pin of the RGB LED
const int greenPin = 13; // GPIO 13 is connected to the green pin
const int bluePin = 12; // GPIO 12 is connected to the blue pin
void setup() {
// Set up the RGB pins as outputs
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Let's start with red
setColor(255, 0, 0); // Red
delay(1000);
// Then mix in some green to make orange
setColor(255, 128, 0); // Orange
delay(1000);
// Full green for yellow
setColor(255, 255, 0); // Yellow
delay(1000);
// Just green
setColor(0, 255, 0); // Green
delay(1000);
// Now blue
setColor(0, 0, 255); // Blue
delay(1000);
// Now Mixing blue and red for indigo
setColor(75, 0, 130); // Indigo
delay(1000);
// Finally, mixing of blue and red for violet
setColor(148, 0, 211); // Violet
delay(1000);
}
// This function sets the color of the RGB LED
void setColor(int red, int green, int blue) {
// We subtract from 255 to invert the logic if using a common anode RGB LED
analogWrite(redPin, 255 - red);
analogWrite(greenPin, 255 - green);
analogWrite(bluePin, 255 - blue);
}