// RGB and R, G, B LED demo for ESP32
const int pinR = 14; // GPIO 14 for red
const int pinG = 13; // GPIO 13 for green
const int pinB = 12; // GPIO 12 for blue
const int potR = 34; // GPIO 34 for potentiometer controlling red
const int potG = 35; // GPIO 35 for potentiometer controlling green
const int potB = 32; // GPIO 32 for potentiometer controlling blue
void setup() {
Serial.begin(115200);
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(potR, INPUT);
pinMode(potG, INPUT);
pinMode(potB, INPUT);
}
int readPot(int pin) {
return map(analogRead(pin), 0, 4095, 0, 255); // The ESP32 ADC has a 12-bit resolution, so the range is 0-4095
}
void loop() {
analogWrite(pinR, readPot(potR));
analogWrite(pinG, readPot(potG));
analogWrite(pinB, readPot(potB));
}