Skip to content

Commit b55a59d

Browse files
committed
Merge branch 'Metallicow-LED-Fix'
2 parents fcc9cf6 + 517f292 commit b55a59d

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

examples/ledangle.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
def led_angle(seconds_to_run_for):
44
# make LED objects
5-
l1 = pyb.Led(1)
6-
l2 = pyb.Led(2)
7-
accel = pyb.Accel()
5+
l1 = pyb.LED(1)
6+
l2 = pyb.LED(2)
7+
accel = pyb.Accel()
88

99
for i in range(20 * seconds_to_run_for):
1010
# get x-axis

examples/switch.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
__doc__ = """
2+
switch.py
3+
=========
4+
5+
Light up some leds when the USR switch on the pyboard is pressed.
6+
7+
Example Usage::
8+
9+
Micro Python v1.0.1 on 2014-05-12; PYBv1.0 with STM32F405RG
10+
Type "help()" for more information.
11+
>>> import switch
12+
>>> switch.run_loop([2, 3])
13+
Loop started.
14+
Press Ctrl+C to break out of the loop.
15+
16+
"""
17+
18+
import pyb
19+
20+
switch = pyb.Switch()
21+
red_led = pyb.LED(1)
22+
green_led = pyb.LED(2)
23+
orange_led = pyb.LED(3)
24+
blue_led = pyb.LED(4)
25+
all_leds = (red_led, green_led, orange_led, blue_led)
26+
27+
def run_loop(leds=all_leds):
28+
"""
29+
Start the loop.
30+
31+
:param `use_leds`: Which LEDs to light up upon switch press.
32+
:type `use_leds`: sequence of LED objects
33+
"""
34+
print('Loop started.\nPress Ctrl+C to break out of the loop.')
35+
while 1:
36+
try:
37+
if switch():
38+
[led.on() for led in leds]
39+
else:
40+
[led.off() for led in leds]
41+
except OSError: # VCPInterrupt # Ctrl+C in interpreter mode.
42+
break
43+
44+
if __name__ == '__main__':
45+
run_loop()

0 commit comments

Comments
 (0)