Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
bf318801
Commit
bf318801
authored
Nov 14, 2016
by
Paul Sokolovsky
Browse files
examples/hwapi: Add uasyncio example of fading 2 LEDs in parallel.
parent
8212773a
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/hwapi/hwconfig_dragonboard410c.py
View file @
bf318801
...
...
@@ -15,5 +15,8 @@ from machine import Pin
# User LED 1 on gpio21
LED
=
Pin
(
21
,
Pin
.
OUT
)
# User LED 2 on gpio120
LED2
=
Pin
(
120
,
Pin
.
OUT
)
# Button S3 on gpio107
BUTTON
=
Pin
(
107
,
Pin
.
IN
)
examples/hwapi/soft_pwm2_uasyncio.py
0 → 100644
View file @
bf318801
# Like soft_pwm_uasyncio.py, but fading 2 LEDs with different phase.
# Also see original soft_pwm.py.
import
uasyncio
from
hwconfig
import
LED
,
LED2
async
def
pwm_cycle
(
led
,
duty
,
cycles
):
duty_off
=
20
-
duty
for
i
in
range
(
cycles
):
if
duty
:
led
.
value
(
1
)
await
uasyncio
.
sleep_ms
(
duty
)
if
duty_off
:
led
.
value
(
0
)
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
.
create_task
(
fade_in_out
(
LED
))
loop
.
call_later_ms_
(
800
,
fade_in_out
(
LED2
))
loop
.
run_forever
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment