const int nColors = 3; // define the number of colors
const int red = 0; // position in the colorPin array for the red pin
const int grn = 1; // position in the colorPin array for the green pin
const int blu = 2; // position in the colorPin array for the blue pin
// Define pin numbers for the RGB LED
const int redPin = 9;
const int grnPin = 10;
const int bluPin = 11;
// Declare the colorPin array globally
const int colorPin[nColors] = {redPin, grnPin, bluPin};
void coloron(int color, int intensity) {
switch (color) {
case red:
analogWrite(colorPin[red], intensity);
break;
case grn:
analogWrite(colorPin[grn], intensity);
break;
case blu:
analogWrite(colorPin[blu], intensity);
break;
}
}
void coloroff(int color) {
analogWrite(colorPin[color], 0);
}
void allColorsOff() {
for (int color = 0; color < nColors; color++) {
coloroff(color);
}
}
void setup() {
pinMode(redPin, OUTPUT);
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
void loop() {
// Generating custom light
coloron(red, 142);
coloron(grn, 002);
coloron(blu, 153);
delay(2000); // Display cyan for 2 seconds
// Turn off all colors
allColorsOff();
}