#include <Servo.h> // Included as allowed package (not used in this example)
const int led1Pin = 2; // PWM pin for led1
const int led2Pin = 3; // PWM pin for led2
const int led3Pin = 4; // PWM pin for led3
// RGB LED rgb1 pins
const int rgb1RedPin = 5; // red channel
const int rgb1GreenPin = 6; // green channel
const int rgb1BluePin = 7; // blue channel
// RGB LED rgb2 pins
const int rgb2RedPin = 8; // red channel
const int rgb2GreenPin = 9; // green channel
const int rgb2BluePin = 10; // blue channel
// Potentiometer analog input pins
const int pot1Pin = A0;
const int pot2Pin = A1;
void setup() {
// Setup LED output pins
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(rgb1RedPin, OUTPUT);
pinMode(rgb1GreenPin, OUTPUT);
pinMode(rgb1BluePin, OUTPUT);
pinMode(rgb2RedPin, OUTPUT);
pinMode(rgb2GreenPin, OUTPUT);
pinMode(rgb2BluePin, OUTPUT);
// No special initialization needed for analog inputs
}
void loop() {
// Read potentiometer values (0-1023)
int pot1Value = analogRead(pot1Pin);
int pot2Value = analogRead(pot2Pin);
// Map potentiometer values to LED brightness 0-255
int led1Brightness = map(pot1Value, 0, 1023, 0, 255);
int led2Brightness = map(pot2Value, 0, 1023, 0, 255);
// Write PWM brightness values to led1 and led2
analogWrite(led1Pin, led1Brightness);
analogWrite(led2Pin, led2Brightness);
// For led3, if both potentiometers are at maximum, turn on LED (full brightness), else off.
if(pot1Value == 1023 && pot2Value == 1023) {
analogWrite(led3Pin, 255);
} else {
analogWrite(led3Pin, 0);
}
// Set RGB LED color gradient.
// The red component is controlled by pot1 and the green component by pot2.
// Normally, blue is off, but if both potentiometers are at maximum, display white (all channels 255).
int redValue = map(pot1Value, 0, 1023, 0, 255);
int greenValue = map(pot2Value, 0, 1023, 0, 255);
int blueValue = 0;
// If both are at maximum, make blue = 255 so that the color becomes white.
if(pot1Value == 1023 && pot2Value == 1023) {
blueValue = 255;
}
// Write the same color to both rgb1 and rgb2
analogWrite(rgb1RedPin, redValue);
analogWrite(rgb1GreenPin, greenValue);
analogWrite(rgb1BluePin, blueValue);
analogWrite(rgb2RedPin, redValue);
analogWrite(rgb2GreenPin, greenValue);
analogWrite(rgb2BluePin, blueValue);
// Loop continuously; a short delay can be added for stability
delay(10);
}