-
Notifications
You must be signed in to change notification settings - Fork 0
/
led_control.py
46 lines (31 loc) · 860 Bytes
/
led_control.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
39
40
41
42
43
44
45
46
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import threading
if __name__ == "__main__":
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
GPIO.setwarnings(False)
def runThread():
for b in LED.blink_list:
pass
class LED:
thread = threading.Thread(target=runThread, daemon=True)
blink_list = []
def __init__(self, pin):
self.pin = pin
GPIO.setup(pin, GPIO.OUT)
LED.thread.start()
def on(self):
GPIO.output(self.pin, GPIO.HIGH)
def off(self):
GPIO.output(self.pin, GPIO.LOW)
def blink(self, interval, duration=0.5):
self.led = (self.pin, interval, duration)
LED.blink_list.append(self.led)
pass
def stop_blink(self):
try:
LED.blink_list.remove(self.led)
except ValueError as e:
pass