Created
October 23, 2013 10:28
-
-
Save yoggy/7116192 to your computer and use it in GitHub Desktop.
GPIO control sample code for Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # | |
| # GPIO control sample code for Raspberry Pi | |
| # | |
| # setup | |
| # $ sudo apt-get update | |
| # $ sudo apt-get install python-rpi.gpio | |
| # | |
| # see also... | |
| # http://elinux.org/RPi_Low-level_peripherals | |
| # http://code.google.com/p/raspberry-gpio-python/wiki/Main | |
| # http://code.google.com/p/raspberry-gpio-python/wiki/Examples | |
| # | |
| import sys | |
| import signal | |
| from time import sleep | |
| import RPi.GPIO as GPIO | |
| pin = 13 # GPIO27 | |
| GPIO.setwarnings(False) | |
| def sigint_handler(signo, frame): | |
| GPIO.output(pin, False) | |
| GPIO.cleanup() | |
| sys.exit(0) | |
| signal.signal(signal.SIGINT, sigint_handler) | |
| # setup | |
| GPIO.setmode(GPIO.BOARD) | |
| GPIO.setup(pin, GPIO.OUT) | |
| while True: | |
| # blink LED | |
| GPIO.output(pin, True) | |
| sleep(0.5) | |
| GPIO.output(pin, False) | |
| sleep(0.5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment