// PWM pins for RGB
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
void setup() {
// Set RGB pins as outputs
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Fade RED from 0 to 255
for (int i = 0; i <= 255; i++) {
setColor(i, 0, 0); // Increase red
delay(40);
}
// Fade GREEN from 0 to 255
for (int i = 0; i <= 255; i++) {
setColor(0, i, 0); // Increase green
delay(50);
}
// Fade BLUE from 0 to 255
for (int i = 0; i <= 255; i++) {
setColor(0, 0, i); // Increase blue
delay(50);
}
// Optionally, fade all back to 0 for a clean loop
for (int i = 255; i >= 0; i--) {
setColor(i, i, i); // Fade all down
delay(50);
}
}
// Function to set RGB values using PWM
void setColor(int red, int green, int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}