Skip to content

Instantly share code, notes, and snippets.

@raster
Last active January 8, 2019 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raster/996bf2ed92276e95e2cd7cdbd72cc7e4 to your computer and use it in GitHub Desktop.
Save raster/996bf2ed92276e95e2cd7cdbd72cc7e4 to your computer and use it in GitHub Desktop.
Simple Python Script for Raspberry Pi
#!/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