Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
9500e984
Commit
9500e984
authored
11 years ago
by
Metallicow
Browse files
Options
Downloads
Patches
Plain Diff
__doc__ switch, make importable, and easy to test
parent
f94cc975
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/switch.py
+34
-17
34 additions, 17 deletions
examples/switch.py
with
34 additions
and
17 deletions
examples/switch.py
+
34
−
17
View file @
9500e984
"""
__doc__
=
"""
switch.py
switch.py
=========
=========
Light up all the leds when the USR switch on the pyboard is pressed.
Light up some leds when the USR switch on the pyboard is pressed.
Example Usage::
Micro Python v1.0.1 on 2014-05-12; PYBv1.0 with STM32F405RG
Type
"
help()
"
for more information.
>>>
import
switch
>>>
switch
.
run_loop
([
2
,
3
])
Loop
started
.
Press
Ctrl
+
C
to
break
out
of
the
loop
.
"""
"""
import
pyb
import
pyb
...
@@ -12,18 +22,25 @@ red_led = pyb.LED(1)
...
@@ -12,18 +22,25 @@ red_led = pyb.LED(1)
green_led
=
pyb
.
LED
(
2
)
green_led
=
pyb
.
LED
(
2
)
orange_led
=
pyb
.
LED
(
3
)
orange_led
=
pyb
.
LED
(
3
)
blue_led
=
pyb
.
LED
(
4
)
blue_led
=
pyb
.
LED
(
4
)
leds
=
[
red_led
,
green_led
,
orange_led
,
blue_led
]
all_
leds
=
[
red_led
,
green_led
,
orange_led
,
blue_led
]
def
run_loop
(
use_leds
=
[]):
"""
Start the loop.
:param `use_leds`: Which leds to light up upon switch press.
:type `use_leds`: list of integers [1-4]
"""
print
(
'
Loop started.
\n
Press Ctrl+C to break out of the loop.
'
)
leds
=
[
all_leds
[
i
-
1
]
for
i
in
use_leds
]
while
1
:
while
1
:
try
:
if
switch
():
if
switch
():
## red_led.on()
## green_led.on()
## orange_led.on()
## blue_led.on()
[
led
.
on
()
for
led
in
leds
]
[
led
.
on
()
for
led
in
leds
]
else
:
else
:
## red_led.off()
## green_led.off()
## orange_led.off()
## blue_led.off()
[
led
.
off
()
for
led
in
leds
]
[
led
.
off
()
for
led
in
leds
]
except
OSError
:
# VCPInterrupt # Ctrl+C in interpreter mode.
break
if
__name__
==
'
__main__
'
:
run_loop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment