-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled.py
More file actions
59 lines (49 loc) · 1.13 KB
/
led.py
File metadata and controls
59 lines (49 loc) · 1.13 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import RPi.GPIO as GP
from gpiozero import LED
from time import sleep
import sys
# LED using gpiozero
def start_led(times=1):
ledTotalLight = times
ledCount = 0
ledBin = 17
led = LED(ledBin)
# Run led many time
while ledCount < ledTotalLight:
print("LED On")
led.on()
sleep(1)
print("LED Off")
led.off()
sleep(.7)
ledCount += 1
# LED using GPIO
def start_led(times=1):
# Set GPIO Mode
GP.setmode(GP.BCM)
# set vars
ledBin = 17
ledTotalLight = times
ledCount = 0
# Setup bin LED bin
GP.setup(ledBin, GP.OUT)
# Run led many time
try:
while ledCount < ledTotalLight:
print("LED On")
GP.output(ledBin, True)
sleep(1)
print("LED Off")
GP.output(ledBin, False)
sleep(.7)
ledCount += 1
finally:
GP.cleanup()
if __name__ == "__main__":
try:
times = int(sys.argv[1])
start_led(times)
except:
print("Few arguments given!\nRun: \n python3 led.py <int times>")
exit(1)