Created
January 26, 2018 07:38
-
-
Save wwj718/78270e363d362c121f51c36b2dd51d6b to your computer and use it in GitHub Desktop.
micropython uasyncio test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See original soft_pwm.py for detailed comments. | |
import uasyncio | |
async def pwm_cycle(led, duty, cycles): | |
duty_off = 20 - duty | |
for i in range(cycles): | |
if duty: | |
print(led) | |
await uasyncio.sleep_ms(duty) | |
if duty_off: | |
print(led) | |
await uasyncio.sleep_ms(duty_off) | |
async def fade_in_out(LED): | |
while True: | |
# Fade in | |
for i in range(1, 21): | |
await pwm_cycle(LED, i, 2) | |
# Fade out | |
for i in range(20, 0, -1): | |
await pwm_cycle(LED, i, 2) | |
loop = uasyncio.get_event_loop() | |
loop.run_until_complete(fade_in_out(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment