Notes
![]() ![]() Notes - notes.io |
import time
from datetime import time as Time, datetime
import threading
import requests
mockResponse = {
"patient": {
"medication": [
{
"name": "test",
"hour": "18:38",
"color": "red",
"pills": [
"paracetamol",
"augment"
],
"createdAt": "2019-10-15T22:53:42.413Z",
"updatedAt": "2019-10-15T22:53:42.413Z",
"__v": 0,
"id": "5da64df6d7b39b48346bd841"
},
{
"name": "asdwe",
"hour": "18:40",
"color": "red",
"pills": [
"parapara",
"augment"
],
"createdAt": "2019-10-15T22:55:02.796Z",
"updatedAt": "2019-10-15T22:55:02.796Z",
"__v": 0,
"id": "5da64e464bb6142c70c30df1"
}
],
"id": "5da636a31c38c31644844940"
}
}
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
coil_A_1_pin = 3
coil_A_2_pin = 17
coil_B_1_pin = 23
coil_B_2_pin = 24
buzzer_pin = 26
led_red_pin = 19
led_green_pin = 13
led_blue_pin = 6
stop_button_pin = 21
medication_refresh_time_interval = 20
isAlarmOn = False
shouldExit = False
StepCount = 4
Seq = range(0, StepCount)
Seq[0] = [1,0,1,0]
Seq[1] = [0,1,1,0]
Seq[2] = [0,1,0,1]
Seq[3] = [1,0,0,1]
colorDict = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1], [1, 1, 0], [0, 1, 1]]
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
GPIO.setup(buzzer_pin, GPIO.OUT)
GPIO.setup(led_red_pin, GPIO.OUT)
GPIO.setup(led_green_pin, GPIO.OUT)
GPIO.setup(led_blue_pin, GPIO.OUT)
GPIO.setup(stop_button_pin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
def buzzer_func():
global isAlarmOn
global shouldExit
while True:
if shouldExit:
break
if not isAlarmOn:
time.sleep(3)
continue
for i in range(1, 4):
GPIO.output(buzzer_pin, 1)
time.sleep(.007)
GPIO.output(buzzer_pin, 0)
time.sleep(.1)
time.sleep(3)
def rgb_led_func():
global isAlarmOn
global shouldExit
count = 0
numberOfColors = len(colorDict)
while True:
if shouldExit:
break
if not isAlarmOn:
time.sleep(3)
continue
GPIO.output(led_red_pin, colorDict[count][0])
GPIO.output(led_green_pin, colorDict[count][1])
GPIO.output(led_blue_pin, colorDict[count][2])
time.sleep(.2)
GPIO.output(led_red_pin, 0)
GPIO.output(led_green_pin, 0)
GPIO.output(led_blue_pin, 0)
time.sleep(.4)
count = count + 1
if count == numberOfColors:
count = 0
def setStep(w1, w2, w3, w4):
GPIO.output(coil_A_1_pin, w1)
GPIO.output(coil_A_2_pin, w2)
GPIO.output(coil_B_1_pin, w3)
GPIO.output(coil_B_2_pin, w4)
def forward(delay, steps):
for i in range(steps):
for j in range(StepCount):
setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
time.sleep(delay)
def motor_func():
global isAlarmOn
global shouldExit
delay = 10
steps = 10
while True:
if shouldExit:
break
if not isAlarmOn:
time.sleep(3)
continue
forward(int(delay) / 1000.0, int(steps))
time.sleep(2.96)
def patients_func():
global shouldExit
while True:
if shouldExit:
break
r = requests.get('http://b84ba0b8.ngrok.io/patients/medication', json={'patientId': '5da636a31c38c31644844940'})
print(r.content)
time.sleep(medication_refresh_time_interval)
def stop_btn_func():
global isAlarmOn
global shouldExit
while True:
if shouldExit:
break
val = GPIO.input(stop_button_pin)
if val == 1:
isAlarmOn = not isAlarmOn
print('Alarm toggled')
time.sleep(.5)
def check_time_func():
global isAlarmOn
global shouldExit
while True:
if shouldExit:
break
currentTime = datetime.now().time()
medications = mockResponse['patient']['medication']
for medication in medications:
medTime = datetime.strptime(medication['hour'], '%H:%M').time()
if medTime.hour == currentTime.hour and medTime.minute == currentTime.minute:
isAlarmOn = True
time.sleep(15)
isAlarmOn = False
break
time.sleep(10)
if __name__ == '__main__':
threading.Thread(target=buzzer_func).start()
threading.Thread(target=rgb_led_func).start()
threading.Thread(target=motor_func).start()
threading.Thread(target=stop_btn_func).start()
#threading.Thread(target=patients_func).start()
threading.Thread(target=check_time_func).start()
while True:
raw_input('Press enter to exit...')
shouldExit = True
setStep(0, 0, 0, 0)
break
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team