# write a micro Python script to control the brightness an LED connected to GPOI 4 with respect to the postion of the potentiometer knob connected to pin no 34 of esp32
from machine import Pin, ADC, PWM
from time import sleep
led = Pin(2, Pin.OUT)
button = Pin(15, Pin.IN)
frequency = 5000
led_pwm = PWM(Pin(4), frequency)
pot = ADC(Pin(34))
pot.width(ADC.WIDTH_10BIT)
pot.atten(ADC.ATTN_11DB)
#led_pwm = PWM(Pin(4), 5000)
while True:
button_state = button.value()
led.value(button_state)
pot_value = pot.read()
led_pwm.duty(pot_value)
sleep(0.1)