Skip to content

Instantly share code, notes, and snippets.

Forked from elktros/
Last active September 1, 2019 10:02
What would you like to do?
LED Blink with Python RPI
#!/usr/bin/env python
import RPi.GPIO as GPIO # RPi.GPIO can be referred as GPIO from now
import time
ledPin = 22 # pin22
def setup():
GPIO.setmode(GPIO.BOARD) # GPIO Numbering of Pins
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
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the destroy() will be executed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment