// RGB LED control with Slider Switches using ESP32
const int pinR = 21; // Red channel (PWM pin)
const int pinG = 22; // Yellow channel (PWM pin)
const int pinB = 23; // Blue channel (PWM pin)
const int sliderR = 34; // Slider switch for Red
const int sliderG = 35; // Slider switch for Yellow
const int sliderB = 32; // Slider switch for Blue
void setup() {
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(sliderR, INPUT);
pinMode(sliderG, INPUT);
pinMode(sliderB, INPUT);
}
int readSlider(int pin) {
return map(analogRead(pin), 0, 4095, 0, 255); // Convert analog value to PWM range (0-255)
}
void loop() {
analogWrite(pinR, readSlider(sliderR)); // Set red color intensity
analogWrite(pinG, readSlider(sliderG)); // Set Yellow color intensity
analogWrite(pinB, readSlider(sliderB)); // Set blue color intensity
}