#define RED_PIN 26 // GPIO 26
#define GREEN_PIN 25 // GPIO 25
#define BLUE_PIN 4 // GPIO 4
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// initialize the LED pins as output
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void setRGBColour(int redValue, int greenValue, int blueValue) {
// analogWrite() automatically constrains these values to 8 bits
// set the LED colors for an RGB LED with a common anode
// invert value since it's common anode
analogWrite(RED_PIN, 255 - redValue);
analogWrite(GREEN_PIN, 255 - greenValue);
analogWrite(BLUE_PIN, 255 - blueValue);
}
void loop() {
// blue light
analogWrite(RED_PIN, 255);
analogWrite(GREEN_PIN, 255);
analogWrite(BLUE_PIN, 0);
delay(1000);
// generate random values between 0 and 255 for each color
int redValue = random(0, 256);
int greenValue = random(0, 256);
int blueValue = random(0, 256);
setRGBColour(redValue, greenValue, blueValue);
delay(1000); // wait one second before changing the colour
}