-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio_component.py
59 lines (48 loc) · 1.46 KB
/
gpio_component.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
47
48
49
50
51
52
53
54
55
56
57
58
59
import RPi.GPIO as GPIO
import time
class gpio:
# Variables
RED_PIN = 21
GREEN_PIN = 20
YELLOW_PIN = 16
LOCK_PIN = 19
UNLOCK_PIN = 26
pins = [RED_PIN, GREEN_PIN, YELLOW_PIN, LOCK_PIN, UNLOCK_PIN]
LED_DURATION = 3 # Seconds
LOCK_DURATION = 0.2 # Seconds
def __init__(self):
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Initialize pins
for pin in self.pins:
GPIO.setup(pin, GPIO.OUT)
def red(self):
print("RED LED ON")
GPIO.output(self.RED_PIN, GPIO.HIGH)
time.sleep(self.LED_DURATION)
print("RED LED OFF")
GPIO.output(self.RED_PIN, GPIO.LOW)
def green(self):
print("GREEN LED ON")
GPIO.output(self.GREEN_PIN, GPIO.HIGH)
time.sleep(self.LED_DURATION)
print("GREEN LED OFF")
GPIO.output(self.GREEN_PIN, GPIO.LOW)
def yellow(self):
print("YELLOW PIN ON")
GPIO.output(self.YELLOW_PIN, GPIO.HIGH)
time.sleep(self.LED_DURATION)
print("LED off")
GPIO.output(self.YELLOW_PIN, GPIO.LOW)
# GPIO 19
def lock(self):
GPIO.output(self.LOCK_PIN, GPIO.HIGH)
print("LOCK")
time.sleep(self.LOCK_DURATION)
GPIO.output(self.LOCK_PIN, GPIO.LOW)
# GPIO 26
def unlock(self):
GPIO.output(self.UNLOCK_PIN, GPIO.HIGH)
print("UNLOCK")
time.sleep(self.LOCK_DURATION)
GPIO.output(self.UNLOCK_PIN, GPIO.LOW)