Skip to content

Instantly share code, notes, and snippets.

@drewgates
Forked from elktros/blinkLed.py
Last active March 18, 2018 20:42
Show Gist options
  • Save drewgates/06365b6b9d4bcdc85072d5d165cd33c6 to your computer and use it in GitHub Desktop.
Save drewgates/06365b6b9d4bcdc85072d5d165cd33c6 to your computer and use it in GitHub Desktop.
How to Blink an LED with Raspberry Pi
#!/usr/bin/env python
import RPi.GPIO as GPIO # RPi.GPIO can be referred as GPIO from now
import time
ledPin = 17 # pin17
def setup():
GPIO.setmode(GPIO.BCM) # Use BCM Pin Numbering to match T-Cobbler Numbering
GPIO.setup(ledPin, GPIO.OUT) # Set ledPin as output
GPIO.output(ledPin, GPIO.LOW) # Set ledPin to LOW to turn Off the LED
def loop():
while True:
print 'LED on'
GPIO.output(ledPin, GPIO.HIGH) # LED On
time.sleep(1.0) # wait 1 sec
print 'LED off'
GPIO.output(ledPin, GPIO.LOW) # LED Off
time.sleep(1.0) # wait 1 sec
def endprogram():
GPIO.output(ledPin, GPIO.LOW) # LED Off
GPIO.cleanup() # Release resources
if __name__ == '__main__': # Program starts from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the destroy() will be executed.
endprogram()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment