-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED_Blinker.py
More file actions
32 lines (27 loc) · 1.09 KB
/
LED_Blinker.py
File metadata and controls
32 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Program to blink a LED continuously.
#!/usr/bin/env python
import RPi.GPIO as GPIO # RPi.GPIO can be referred as GPIO from now
import time
#220 ohm resistor
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
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the destroy() will be executed.
endprogram()