Created
December 11, 2019 03:26
-
-
Save choowilson/81c651ea7296d111bcb685ca560cbbb1 to your computer and use it in GitHub Desktop.
example python script to switch on GPIO pin on Raspi
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
import RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BOARD) # Raspi board GPIO Pin Number | |
GPIO.setup(11, GPIO.OUT) # Output pin is GPIO Pin 17 | |
# Initial state for LEDs: | |
print("Testing GPIO Pin11 out, Press CTRL+C to exit") | |
try: | |
print("Set GPIO 17 HIGH") | |
GPIO.output(11, GPIO.HIGH) | |
time.sleep(5) | |
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly: | |
print("Keyboard interrupt") | |
except: | |
print("some error") | |
finally: | |
print("clean up") | |
GPIO.cleanup() # cleanup all GPIO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment