Last active
January 8, 2019 17:56
-
-
Save raster/996bf2ed92276e95e2cd7cdbd72cc7e4 to your computer and use it in GitHub Desktop.
Simple Python Script for Raspberry Pi
This file contains 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/python3 | |
# external module imports | |
import RPi.GPIO | |
import time | |
# button and LED assignment | |
button = 26 | |
led = 19 | |
# ignores GPIO errors | |
RPi.GPIO.setwarnings(False) | |
# pin setup | |
RPi.GPIO.setmode(RPi.GPIO.BCM) | |
# button pin set as input with pull-up | |
RPi.GPIO.setup(button, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP) | |
# LED pin set as output | |
RPi.GPIO.setup(led, RPi.GPIO.OUT) | |
while True: | |
if RPi.GPIO.input(button) == RPi.GPIO.LOW: | |
print("The button was pressed") | |
RPi.GPIO.output(led,RPi.GPIO.HIGH) | |
time.sleep(0.1) | |
else: | |
RPi.GPIO.output(led,RPi.GPIO.LOW) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment