# Example using PWM to fade an LED. # note: 65535 = 100% duty cycle # 0 = 0% duty cycle # PWM is an 8-bit number, shifted left 8x import time from machine import Pin, PWM # Construct PWM object, with LED on Pin(25) pwm = PWM(Pin(16)) # Set the PWM frequency. pwm.freq(1000) # Fade the LED in and out a few times. duty = 0 direction = 1 while(1): duty += direction if duty > 255: duty = 255 direction = -1 elif duty < 0: duty = 0 direction = 1 pwm.duty_u16(duty << 8) time.sleep(0.002)