# Example using PWM to fade an LED. # Currently set up to go from 0.5ms to 3.0ms pulse widths # similar to what's used to drive a servo motor import time from machine import Pin, PWM # Construct PWM object, with LED on Pin(25) pwmX = PWM(Pin(16)) pwmY = PWM(Pin(17)) pwmZ = PWM(Pin(18)) # Set the PWM frequency. pwmX.freq(50) pwmY.freq(50) pwmZ.freq(50) # Fade the LED in and out a few times. dutyX = 655 dutyY = 3176 # 1.00ms dutyZ = 6553 # 2.00ms direction = 1 # At 50Hz (20ms) # 3.0ms PW = 9830 duty cycle (3992/65536) # 0.5ms PW = 1638 duty cycle (655/65536) while(1): dutyX += direction if dutyX > 9830: dutyX = 9830 direction = -1 elif dutyX < 1638: dutyX = 1638 direction = 1 pwmX.duty_u16(dutyX) pwmY.duty_u16(dutyY) pwmZ.duty_u16(dutyZ) time.sleep(0.002)