from machine import ADC, Pin, PWM # import ADC, Pin and PWM classes
import time # import time module
adc = ADC(26) # create ADC object from Pin26
pwm = PWM(Pin(15)) # create PWM object from Pin15
pwm.freq(1000) # set PWM frequency to 1kHz
try: # if have no error, run the program between try: and except:
while True: # create an infinite loop
adcValue = adc.read_u16() # read ADC value
pwm.duty_u16(adcValue) # set PWM duty cycle
time.sleep(0.1) # sleep 100 milliseconds
except: # if have error, run the program between except:
pwm.deinit() # turn off PWM