-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_8Led.py
executable file
·35 lines (29 loc) · 909 Bytes
/
03_8Led.py
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
#!/usr/bin/env python
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.05)
GPIO.output(pin, GPIO.HIGH)
for pin in reversed(pins):
GPIO.output(pin, GPIO.LOW)
time.sleep(0.05)
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()