/*
control led brightness
*/
#define POTENTIOMETER_PIN 35 //ESP32 pin connected to pontentiometer pin
#define LED_PIN 26 //ESP32 pin connected to LED pin
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600) ;
//declare LED pin to be an output:
pinMode(LED_PIN, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// reads input on analog pin A0
int analogvalue = analogRead(POTENTIOMETER_PIN);
//scales it to brightness (value between 0 - 255)
int brightness = map(analogvalue, 0, 4095, 0, 255);
//set the brightness LED that connect to pin 3
analogWrite(LED_PIN, brightness);
//print out the value
Serial.print("Analog value = ");
Serial.print(analogvalue);
Serial.print(" => brightness = ");
Serial.println(brightness);
delay(100);
}