const int ledPin = 16; // 16 corresponds to GPIO16
const int ledPin2 = 17; // 17 corresponds to GPIO17
const int ledPin3 = 5; // 5 corresponds to GPIO5
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup(){
Serial.begin(11520);
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
ledcAttachPin(ledPin2, ledChannel);
ledcAttachPin(ledPin3, ledChannel);
}
void loop() {
// read the potentiometer value (0-4095)
potValue = analogRead(potPin);
// map the potentiometer value to the PWM range (0-255)
int ledBrightness = map(potValue, 0, 4095, 0, 255);
// set the LED brightness
ledcWrite(ledChannel, ledBrightness);
ledcWrite(ledChannel, ledBrightness); // Adjust as needed for LED 2
ledcWrite(ledChannel, ledBrightness); // Adjust as needed for LED 3
// print potentiometer value and LED brightness to serial monitor
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print("LED Brightness: ");
Serial.println(ledBrightness);
delay(1000); // Add a small delay to avoid excessive serial output
}