楼主: 驴友花雕
|
[MP动手做] MicroPython动手做(36)——MixPY之Hello world |
7、随机变色的LED [mw_shl_code=python,false]#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] |
本帖最后由 驴友花雕 于 2020-6-30 16:38 编辑 8、PWM使板载灯呼吸灯效果 [mw_shl_code=python,false]#MicroPython动手做(36)——MixPY之Hello world #PWM使板载灯呼吸灯效果 import time import mixno from machine import Timer from machine import PWM tim2 = Timer(Timer.TIMER2,Timer.CHANNEL0, mode=Timer.MODE_PWM) pin13 = PWM(tim2,freq=500000,duty=0, pin=mixno.pin_D[13]) while True: for i in range(0, 100, 1): pin13.duty(i) time.sleep_ms(10) for i in range(100, 0, -1): pin13.duty(i) time.sleep_ms(10)[/mw_shl_code] |
9、蓝色PWM呼吸灯 [mw_shl_code=python,false]#MicroPython动手做(36)——MixPY之Hello world #蓝色PWM呼吸灯 import time import mixno from machine import Timer from machine import PWM 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_B.duty(100-i) time.sleep_ms(13) time.sleep_ms(100) for i in range(100, 0, -1): LED_B.duty(100-i) time.sleep_ms(13) time.sleep_ms(100)[/mw_shl_code] |
10、多彩PWM呼吸灯 [mw_shl_code=python,false]#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)[/mw_shl_code] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed