2019-12-13 00:43:17 -05:00
|
|
|
import os, pyb
|
2014-05-03 11:43:27 -04:00
|
|
|
|
2019-12-13 00:43:17 -05:00
|
|
|
machine = os.uname().machine
|
|
|
|
if 'PYBv1.' in machine or 'PYBLITEv1.' in machine:
|
|
|
|
leds = [pyb.LED(i) for i in range(1, 5)]
|
|
|
|
pwm_leds = leds[2:]
|
|
|
|
elif 'PYBD' in machine:
|
|
|
|
leds = [pyb.LED(i) for i in range(1, 4)]
|
|
|
|
pwm_leds = []
|
|
|
|
else:
|
|
|
|
print('SKIP')
|
|
|
|
raise SystemExit
|
2014-05-03 11:43:27 -04:00
|
|
|
|
2016-01-29 18:12:59 -05:00
|
|
|
# test printing
|
2019-12-13 00:43:17 -05:00
|
|
|
for i in range(3):
|
|
|
|
print(leds[i])
|
2014-05-03 11:43:27 -04:00
|
|
|
|
2016-01-29 18:12:59 -05:00
|
|
|
# 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)
|