1import os, pyb 2 3machine = os.uname().machine 4if "PYBv1." in machine or "PYBLITEv1." in machine: 5 leds = [pyb.LED(i) for i in range(1, 5)] 6 pwm_leds = leds[2:] 7elif "PYBD" in machine: 8 leds = [pyb.LED(i) for i in range(1, 4)] 9 pwm_leds = [] 10else: 11 print("SKIP") 12 raise SystemExit 13 14# test printing 15for i in range(3): 16 print(leds[i]) 17 18# test on and off 19for l in leds: 20 l.on() 21 assert l.intensity() == 255 22 pyb.delay(100) 23 l.off() 24 assert l.intensity() == 0 25 pyb.delay(100) 26 27# test toggle 28for l in 2 * leds: 29 l.toggle() 30 assert l.intensity() in (0, 255) 31 pyb.delay(100) 32 33# test intensity 34for l in pwm_leds: 35 for i in range(256): 36 l.intensity(i) 37 assert l.intensity() == i 38 pyb.delay(1) 39 for i in range(255, -1, -1): 40 l.intensity(i) 41 assert l.intensity() == i 42 pyb.delay(1) 43