forked from pikhena/MedCareFinal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
74 lines (50 loc) · 1.29 KB
/
script.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
69
70
71
72
from firebase import firebase
import time
import threading
from time import sleep
import RPi.GPIO as GPIO
FBConn = firebase.FirebaseApplication('https://medcare-c3184.firebaseio.com/', None)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.SETUP(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
buzzer=23
GPIO.setup(buzzer, GPIO.OUT)
previous = "null"
while True:
state = GPIO.input(21)
print(state)
if state == 0 and previous == "open" or state == 0 and previous == "null":
pill = str("bad")
data_to_upload = {
'pillTaken' : pill
}
result = FBConn.patch('/Update', data_to_upload)
previous = "closed"
GPIO.output(buzzer, GPIO.LOW)
print ("Alarm Beep")
sleep(10)
GPIO.output(buzzer, GPIO.HIGH)
print ("No Alarm Beep")
sleep(0.5)
GPIO.output(buzzer, GPIO.LOW)
print ("Alarm Beep")
sleep(5)
GPIO.output(buzzer, GPIO.HIGH)
print ("No Alarm Beep")
sleep(0.5)
GPIO.output(buzzer, GPIO.LOW)
print ("Alarm Beep")
sleep(5)
GPIO.output(buzzer, GPIO.HIGH)
print ("No Alarm Beep")
sleep(0.5)
print('Circuit Closed.')
if state == 1 and previous == "closed" or state == 1 and previous == "null":
pill = str("good")
data_to_upload = {
'pillTaken' : pill
}
result = FBConn.patch('/Update', data_to_upload)
previous = "open"
sleep(1)
GPIO.cleanup(21)