-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path07_flowingLed.py
More file actions
executable file
·41 lines (33 loc) · 1.07 KB
/
07_flowingLed.py
File metadata and controls
executable file
·41 lines (33 loc) · 1.07 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
33
34
35
36
37
38
39
40
#!/usr/bin/env python
#-----------------------------------------------------------
# File name : 07_flowingLed.py
# Description : flowing LED
# Author : Jason
# E-mail : jason@adeept.com
# Website : www.adeept.com
# Date : 2015/06/12
#-----------------------------------------------------------
import RPi.GPIO as GPIO
import time
pins = [11, 12, 13, 15, 16, 18, 22, 7]
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
for pin in pins:
GPIO.setup(pin, GPIO.OUT) # Set all pins' mode is output
GPIO.output(pin, GPIO.HIGH) # Set all pins to high(+3.3V) to off led
def loop():
while True:
for pin in pins:
GPIO.output(pin, GPIO.LOW)
time.sleep(0.2)
GPIO.output(pin, GPIO.HIGH)
def destroy():
for pin in pins:
GPIO.output(pin, GPIO.HIGH) # turn off all leds
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()