File tree 2 files changed +48
-3
lines changed
2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
def led_angle (seconds_to_run_for ):
4
4
# 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 ()
8
8
9
9
for i in range (20 * seconds_to_run_for ):
10
10
# get x-axis
Original file line number Diff line number Diff line change
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.\n Press 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 ()
You can’t perform that action at this time.
0 commit comments