//Nama : Irfansyah Peradeniya
//NIM : 22/492986/PA/21156
//Prodi : Elektronika dan Instrumentasi
// 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/
//
const int ledPin = 16;
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
void setup() {
Serial.begin(115200);
pinMode(potPin, INPUT);
pinMode(ledPin, OUTPUT);
ledcSetup(1, 5000, 8);
ledcAttachPin(ledPin, 1);
delay(1000);
}
void loop() {
// Reading potentiometer value
potValue = analogRead(potPin);
potValue=map(potValue, 0, 4095, 0, 255);
ledcWrite(1,potValue);
Serial.println(potValue);
delay(500);
}