|
楼主 |
发表于 2020-6-30 15:40
|
显示全部楼层
7、随机变色的LED
[mw_shl_code=arduino,true]#MicroPython动手做(36)——MixPY之Hello world
#随机变色的LED
import time
import random
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:
i = random.randint(0, 100)
time.sleep_ms(300)
LED_R.duty(100-i)
j = random.randint(0, 100)
time.sleep_ms(300)
LED_G.duty(100-j)
k = random.randint(0, 100)
time.sleep_ms(300)
LED_B.duty(100-k)[/mw_shl_code]
|
|