-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalve.py
68 lines (47 loc) · 1.52 KB
/
valve.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
60
61
62
63
64
65
66
67
68
from time import sleep
import logging
try:
import RPi.GPIO as GPIO
def init_valve(valve):
logging.info("Valve: Initing %s valve!", valve)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(valve[0], GPIO.OUT)
GPIO.setup(valve[1], GPIO.OUT)
close_valve(valve)
def open_valve(valve):
logging.info("Valve: Opening %s valve!", valve)
GPIO.output(valve[0], GPIO.HIGH)
GPIO.output(valve[1], GPIO.LOW)
sleep(5)
GPIO.output(valve[0], GPIO.LOW)
def close_valve(valve):
logging.info("Valve: Closing %s valve!", valve)
GPIO.output(valve[0], GPIO.LOW)
GPIO.output(valve[1], GPIO.HIGH)
sleep(5)
GPIO.output(valve[1], GPIO.LOW)
except ModuleNotFoundError:
logging.warning("Valve: Could not import GPIO")
def init_valve(valve=None):
logging.info("Valve: Initing %s valve!", valve)
def open_valve(valve=None):
logging.info("Valve: Opening %s valve!", valve)
def close_valve(valve=None):
logging.info("Valve: Closing %s valve!", valve)
if __name__ == "__main__":
BLUE = [17, 18]
BLACK = [22, 23]
init_valve(BLUE)
init_valve(BLACK)
while True:
command = input("Enter a command: ")
if command == "or":
open_valve(BLUE)
elif command == "ol":
open_valve(BLACK)
elif command == "cr":
close_valve(BLUE)
elif command == "cl":
close_valve(BLACK)
continue