|
楼主 |
发表于 2020-7-4 10:58
|
显示全部楼层
10、多彩PWM呼吸灯
- #MicroPython动手做(36)——MixPY之Hello world
- #多彩PWM呼吸灯
- import time
- import mixno
- from machine import Timer
- from machine import PWM
- tim_LED_R = Timer(Timer.TIMER0, Timer.CHANNEL3, mode=Timer.MODE_PWM)
- LED_R=PWM(tim_LED_R, freq=500000, duty=100, pin=mixno.pin_D[7])
- tim_LED_G = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)
- LED_G=PWM(tim_LED_G, freq=500000, duty=100, pin=mixno.pin_D[6])
- tim_LED_B = Timer(Timer.TIMER2, Timer.CHANNEL3, mode=Timer.MODE_PWM)
- LED_B=PWM(tim_LED_B, freq=500000, duty=100, pin=mixno.pin_D[8])
- while True:
- for i in range(0, 100, 1):
- LED_G.duty(100-i)
- LED_R.duty(100-i)
- time.sleep_ms(20)
- time.sleep_ms(400)
- for i in range(100, 0, -1):
- LED_R.duty(100-i)
- LED_B.duty(100-i)
- time.sleep_ms(20)
- time.sleep_ms(400)
复制代码
|
|