/*
Name : Aditya Kyran Santoso
Class : Microcontroller IUP
Modify the ESP32 simulation with a potentiometer
and an LED attached to the GPIO16 (with a 470-ohm resistor),
the LED lights up following the rotation of the
potentiometer (starting from OFF to full 100%)
using ADC and PWM reading techniques for LEDs
Share your link in the field in eLok according to the task given
Enjoy your work.
Reference
https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
https://randomnerdtutorials.com/esp32-digital-inputs-outputs-arduino/
https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/
*/
// setting pin numbers
const int potPin = 34; // potentiometer is connected to GPIO 34 (analog ADC1_CH6)
const int ledPin = 16; // LED is connected to GPIO 16 (analog UART 2 RX)
// setting PWM properties
const int freq = 1000;
const int ledChannel = 0;
const int resolution = 12; // 12-bit resolution (0 - 4096)
int potValue = 0; // variable for storing the potentiometer value
void setup()
{
ledcSetup(ledChannel, freq, resolution); // configure LED PWM functionalitites
ledcAttachPin(ledPin, ledChannel);
Serial.begin(115200);
delay(500);
}
void loop()
{
potValue = analogRead(potPin); // reading potentiometer value
ledcWrite(ledChannel, potValue); // changing the LED brightness with PWM
Serial.println(potValue);
delay(500);
}