Last active
January 10, 2016 03:30
-
-
Save aansubarkah/bfda4ac0342ab3835594 to your computer and use it in GitHub Desktop.
python script to manipulate LED with Raspberry Pi 2 + Switch Tactile
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
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