Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Embedded Systems
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
my_awesome_code
Embedded Systems
Commits
fa282a98
Commit
fa282a98
authored
3 months ago
by
s84716
Browse files
Options
Downloads
Patches
Plain Diff
led switch
parent
fe77e80d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
led_switch2.py
+38
-0
38 additions, 0 deletions
led_switch2.py
with
38 additions
and
0 deletions
led_switch2.py
0 → 100644
+
38
−
0
View file @
fa282a98
#!/usr/bin/python3
import
RPi.GPIO
as
GPIO
import
time
,
sys
# use pin numbers
GPIO
.
setmode
(
GPIO
.
BOARD
)
# use pin 12 for output (=GPIO18)
GPIO
.
setup
(
12
,
GPIO
.
OUT
)
ledOn
=
False
GPIO
.
output
(
12
,
ledOn
)
# use pin 22 for input (=GPIO25)
GPIO
.
setup
(
22
,
GPIO
.
IN
)
# callback function to switch LED output
def
switch_led
(
pin
):
global
ledOn
ledOn
=
not
ledOn
# switch
# write to pin 12
GPIO
.
output
(
12
,
ledOn
)
return
# detect the event of rising signal level at pin 22
GPIO
.
add_event_detect
(
22
,
GPIO
.
RISING
,
bouncetime
=
200
)
# in case of an event switch LED output using
#the callback function switch_led(pin)
GPIO
.
add_event_callback
(
22
,
switch_led
)
try
:
while
True
:
time
.
sleep
(
1
)
# interrupt using <Ctrl>+<c>
except
KeyboardInterrupt
:
# release used pins and return
GPIO
.
cleanup
()
sys
.
exit
()
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