-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_flowingLedMyVersion.py
39 lines (31 loc) · 1013 Bytes
/
06_flowingLedMyVersion.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
35
36
37
38
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
from itertools import cycle
pins = [11, 12, 13, 15, 16, 18, 22, 7]
pincycle = cycle(pins)
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 pincycle:
nextpin = pin
nextpin = next(pincycle)
GPIO.output(pin, GPIO.LOW)
GPIO.output(nextpin, GPIO.LOW)
time.sleep(0.3)
GPIO.output(pin, GPIO.HIGH)
GPIO.output(nextpin, 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()