from machine import Pin, ADC, PWM
# from utime import sleep
import time
# led = Pin(16, Pin.OUT)
# button = Pin(15, Pin.IN, Pin.PULL_DOWN)
# while True:
# # print(button.value())
# if button.value() == 1:
# # start = time.tick_ms()
# # print(start)
# led.value(1)
# else:
# led.value(0)
# # end = time.tick_ms()
# # delta = end-start
# # print(f"Time difference: {delta}s")
# time.sleep(.1)
# pot_pin = ADC(Pin(26))
# conversion_factor = 3.3/65535
# while True:
# pot_voltage = pot_pin.read_u16()*conversion_factor
# print(pot_voltage)
# time.sleep(0.1)
# Control the brightness of the LED
pot_pin = ADC(Pin(26))
pwm_pin = PWM(Pin(16))
pwm_pin.freq(1000)
while True:
pot_value = pot_pin.read_u16()
pwm_pin.duty_u16(pot_value)
print(pot_value)
time.sleep(0.1)