Skip to content

Instantly share code, notes, and snippets.

@aansubarkah
Last active January 10, 2016 03:30
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 aansubarkah/bfda4ac0342ab3835594 to your computer and use it in GitHub Desktop.
Save aansubarkah/bfda4ac0342ab3835594 to your computer and use it in GitHub Desktop.
python script to manipulate LED with Raspberry Pi 2 + Switch Tactile
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # predefined GPIO 26 a.k.a pin #37
GPIO.setup(4, GPIO.OUT, initial=GPIO.LOW) # predefined GPIO 4 a.k.a pin #7
while True: # loop forever, terminate script by ctrl + c
switchPress = GPIO.input(26) # listen to GPIO 26
if switchPress: # if switch button pressed
GPIO.output(4, GPIO.HIGH) # set GPIO 4 to high, LED turn on
if switchPress == False: # if switch button released
GPIO.output(4, GPIO.LOW) # send LOW to GPIO 4
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment