from machine import Pin, PWM, ADC
pwm = PWM(Pin(15))
adc = ADC(Pin(28))
button = Pin(14, Pin.IN, Pin.PULL_UP)
pwm.freq(1000)
led_on = False
while True:
duty = adc.read_u16()
pwm.duty_u16(duty)
button_state = button.value()
if button_state == 0:
led_on = not led_on
if led_on:
pwm.duty_u16(65535)
else:
pwm.duty_u16(0)