We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fa82aa8 commit f94cc97Copy full SHA for f94cc97
examples/switch.py
@@ -0,0 +1,29 @@
1
+"""
2
+switch.py
3
+=========
4
+
5
+Light up all the leds when the USR switch on the pyboard is pressed.
6
7
8
+import pyb
9
10
+switch = pyb.Switch()
11
+red_led = pyb.LED(1)
12
+green_led = pyb.LED(2)
13
+orange_led = pyb.LED(3)
14
+blue_led = pyb.LED(4)
15
+leds = [red_led, green_led, orange_led, blue_led]
16
17
+while 1:
18
+ if switch():
19
+ ## red_led.on()
20
+ ## green_led.on()
21
+ ## orange_led.on()
22
+ ## blue_led.on()
23
+ [led.on() for led in leds]
24
+ else:
25
+ ## red_led.off()
26
+ ## green_led.off()
27
+ ## orange_led.off()
28
+ ## blue_led.off()
29
+ [led.off() for led in leds]
0 commit comments