summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMetallicow <metaliobovinus@gmail.com>2014-05-31 23:15:04 -0600
committerMetallicow <metaliobovinus@gmail.com>2014-05-31 23:15:04 -0600
commitf94cc975a2aca94afc0a8df7bbdeaa276ca5b5a7 (patch)
tree53d2e65e80df8b9b9062d187707d71cf5dc8b41c
parentfa82aa81c03bba74be013b7e39ab1270477b5cc3 (diff)
downloadmicropython-f94cc975a2aca94afc0a8df7bbdeaa276ca5b5a7.tar.gz
micropython-f94cc975a2aca94afc0a8df7bbdeaa276ca5b5a7.zip
Add switch test example
-rw-r--r--examples/switch.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/switch.py b/examples/switch.py
new file mode 100644
index 0000000000..d2bdad040e
--- /dev/null
+++ b/examples/switch.py
@@ -0,0 +1,29 @@
+"""
+switch.py
+=========
+
+Light up all the leds when the USR switch on the pyboard is pressed.
+"""
+
+import pyb
+
+switch = pyb.Switch()
+red_led = pyb.LED(1)
+green_led = pyb.LED(2)
+orange_led = pyb.LED(3)
+blue_led = pyb.LED(4)
+leds = [red_led, green_led, orange_led, blue_led]
+
+while 1:
+ if switch():
+ ## red_led.on()
+ ## green_led.on()
+ ## orange_led.on()
+ ## blue_led.on()
+ [led.on() for led in leds]
+ else:
+ ## red_led.off()
+ ## green_led.off()
+ ## orange_led.off()
+ ## blue_led.off()
+ [led.off() for led in leds]