Skip to content

Instantly share code, notes, and snippets.

@Rassilion
Created December 4, 2015 18:20
Show Gist options
  • Save Rassilion/ac5f8c33d921f7a63c6c to your computer and use it in GitHub Desktop.
Save Rassilion/ac5f8c33d921f7a63c6c to your computer and use it in GitHub Desktop.
Raspberry Pi tests with button and leds
#Raspberry Pi GPIO led blink and button
import RPi.GPIO as GPIO
import time
import sys
# blinking function
def blink(pin):
GPIO.output(pin,GPIO.HIGH)
time.sleep(1)
GPIO.output(pin,GPIO.LOW)
time.sleep(1)
return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
# set up GPIO input channel
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True:
blink(11)
input_state = GPIO.input(3)
if input_state == False:
blink(13)
time.sleep(0.4)
except KeyboardInterrupt:
GPIO.cleanup()
sys.exit(1)
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment