We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 30cfdc2 commit 99e5badCopy full SHA for 99e5bad
1 file changed
examples/hwapi/soft_pwm_uasyncio.py
@@ -0,0 +1,28 @@
1
+# See original soft_pwm.py for detailed comments.
2
+import uasyncio
3
+from hwconfig import LED
4
+
5
6
+async def pwm_cycle(led, duty, cycles):
7
+ duty_off = 20 - duty
8
+ for i in range(cycles):
9
+ if duty:
10
+ led.value(1)
11
+ await uasyncio.sleep_ms(duty)
12
+ if duty_off:
13
+ led.value(0)
14
+ await uasyncio.sleep_ms(duty_off)
15
16
17
+async def fade_in_out(LED):
18
+ while True:
19
+ # Fade in
20
+ for i in range(1, 21):
21
+ await pwm_cycle(LED, i, 2)
22
+ # Fade out
23
+ for i in range(20, 0, -1):
24
25
26
27
+loop = uasyncio.get_event_loop()
28
+loop.run_until_complete(fade_in_out(LED))
0 commit comments