// Define pins for single-color LED
const int led1Pin = 2;
// Define pins for RGB LED 1
const int rgb1RPin = 3;
const int rgb1GPin = 4;
const int rgb1BPin = 5;
// Define pins for RGB LED 2
const int rgb2RPin = 6;
const int rgb2GPin = 7;
const int rgb2BPin = 8;
// Define pins for RGB LED 3
const int rgb3RPin = 9;
const int rgb3GPin = 10;
const int rgb3BPin = 11;
// Define timing variables
unsigned long previousMillisLed1 = 0;
unsigned long previousMillisRGB = 0;
const long intervalLed1 = 2000; // 2 seconds
const long intervalRGB = 2000; // 2 seconds
// Define RGB color sequence
const int numColors = 7;
int colorIndex = 0;
int colors[numColors][3] = {
{255, 0, 0}, // Red
{0, 255, 0}, // Green
{0, 0, 255}, // Blue
{255, 255, 0}, // Yellow
{0, 255, 255}, // Cyan
{255, 0, 255}, // Magenta
{255, 255, 255} // White
};
// Define LED state
bool led1State = false;
void setup() {
// Initialize single-color LED pin as output
pinMode(led1Pin, OUTPUT);
// Initialize RGB LED pins as outputs
pinMode(rgb1RPin, OUTPUT);
pinMode(rgb1GPin, OUTPUT);
pinMode(rgb1BPin, OUTPUT);
pinMode(rgb2RPin, OUTPUT);
pinMode(rgb2GPin, OUTPUT);
pinMode(rgb2BPin, OUTPUT);
pinMode(rgb3RPin, OUTPUT);
pinMode(rgb3GPin, OUTPUT);
pinMode(rgb3BPin, OUTPUT);
// Set initial state for single-color LED (off)
digitalWrite(led1Pin, LOW);
// Set initial color for RGB LEDs (Red)
setRGBColor(colors[0][0], colors[0][1], colors[0][2]);
// Initialize timing variables to current time
previousMillisLed1 = millis();
previousMillisRGB = millis();
}
void loop() {
unsigned long currentMillis = millis();
// Check if it's time to toggle the single-color LED
if (currentMillis - previousMillisLed1 >= intervalLed1) {
previousMillisLed1 = currentMillis;
led1State = !led1State;
digitalWrite(led1Pin, led1State ? HIGH : LOW);
}
// Check if it's time to change the RGB LED colors
if (currentMillis - previousMillisRGB >= intervalRGB) {
previousMillisRGB = currentMillis;
colorIndex = (colorIndex + 1) % numColors;
setRGBColor(colors[colorIndex][0], colors[colorIndex][1], colors[colorIndex][2]);
}
}
// Function to set the color of all RGB LEDs
void setRGBColor(int red, int green, int blue) {
// Set color for RGB LED 1
analogWrite(rgb1RPin, red);
analogWrite(rgb1GPin, green);
analogWrite(rgb1BPin, blue);
// Set color for RGB LED 2
analogWrite(rgb2RPin, red);
analogWrite(rgb2GPin, green);
analogWrite(rgb2BPin, blue);
// Set color for RGB LED 3
analogWrite(rgb3RPin, red);
analogWrite(rgb3GPin, green);
analogWrite(rgb3BPin, blue);
}
mega:SCL
mega:SDA
mega:AREF
mega:GND.1
mega:13
mega:12
mega:11
mega:10
mega:9
mega:8
mega:7
mega:6
mega:5
mega:4
mega:3
mega:2
mega:1
mega:0
mega:14
mega:15
mega:16
mega:17
mega:18
mega:19
mega:20
mega:21
mega:5V.1
mega:5V.2
mega:22
mega:23
mega:24
mega:25
mega:26
mega:27
mega:28
mega:29
mega:30
mega:31
mega:32
mega:33
mega:34
mega:35
mega:36
mega:37
mega:38
mega:39
mega:40
mega:41
mega:42
mega:43
mega:44
mega:45
mega:46
mega:47
mega:48
mega:49
mega:50
mega:51
mega:52
mega:53
mega:GND.4
mega:GND.5
mega:IOREF
mega:RESET
mega:3.3V
mega:5V
mega:GND.2
mega:GND.3
mega:VIN
mega:A0
mega:A1
mega:A2
mega:A3
mega:A4
mega:A5
mega:A6
mega:A7
mega:A8
mega:A9
mega:A10
mega:A11
mega:A12
mega:A13
mega:A14
mega:A15
led1:A
led1:C
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
rgb2:R
rgb2:COM
rgb2:G
rgb2:B
rgb3:R
rgb3:COM
rgb3:G
rgb3:B