forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathled.py
40 lines (34 loc) · 712 Bytes
/
led.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pyb
from pyb import LED
l1 = pyb.LED(1)
l2 = pyb.LED(2)
l3 = pyb.LED(3)
l4 = pyb.LED(4)
leds = [LED(i) for i in range(1, 5)]
pwm_leds = leds[2:]
# test printing
for l in leds:
print(l)
# test on and off
for l in leds:
l.on()
assert l.intensity() == 255
pyb.delay(100)
l.off()
assert l.intensity() == 0
pyb.delay(100)
# test toggle
for l in 2 * leds:
l.toggle()
assert l.intensity() in (0, 255)
pyb.delay(100)
# test intensity
for l in pwm_leds:
for i in range(256):
l.intensity(i)
assert l.intensity() == i
pyb.delay(1)
for i in range(255, -1, -1):
l.intensity(i)
assert l.intensity() == i
pyb.delay(1)