-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddDosing.py
36 lines (29 loc) · 898 Bytes
/
addDosing.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
import RPi.GPIO as GPIO
import time
import sys
import datetime
GPIO.setmode(GPIO.BCM)
pinList = [2, 3, 4, 17, 27, 22, 10, 9 ]
try:
sleep=int(sys.argv[1])
relay = int(sys.argv[2])
GPIO.setup(pinList[relay-1], GPIO.OUT)
GPIO.output(pinList[relay-1], GPIO.HIGH)
amount = float(sleep)/10*2.5
print "Dosing #",relay,"\tAmount:",str(amount),"mL"
with open("/home/pi/relay"+str(relay)+".py", "w") as myfile:
myfile.write("relay"+str(relay)+"LastAdded=\""+str(datetime.datetime.utcnow().isoformat())+"\"\nrelay"+str(relay)+"Volume="+str(amount)+"\n")
GPIO.output(pinList[relay-1], GPIO.LOW)
for i in range(0,sleep):
print i
time.sleep(0.1)
GPIO.output(pinList[relay-1], GPIO.HIGH)
except KeyboardInterrupt:
print "Stopping"
except Exception, e:
print "Unexpected error!"
print e
raise
finally:
GPIO.output(pinList[relay-1], GPIO.HIGH)
print "Relay Off"