Fade example script (phyduino.py) Fades the on-board LED up and down with PWM, about once every three seconds. The duty cycle goes from 0 (off) to 65535 (fully on) in 51 steps, 30 ms apart, then back down.
- Uses
- pwm()
import time
import phyduino as mcu
STEP = 1285
led = mcu.pwm("LED")
brightness = 0
fade_amount = STEP
while True:
led.duty_u16(brightness)
brightness += fade_amount
if brightness <= 0 or brightness >= 65535:
fade_amount = -fade_amount
time.sleep(0.03)