-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartCrib.py
50 lines (41 loc) · 1.48 KB
/
SmartCrib.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
import RPi.GPIO as GPIO
import os
import time
import simpleaudio as sa
soundChannel = 10
movementChannel = 7
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(soundChannel, GPIO.IN)
GPIO.setup(movementChannel, GPIO.IN)
filename = 'relaxingMusic.wav'
wave_obj = sa.WaveObject.from_wave_file(filename)
def detectSound(channel):
if GPIO.input(channel):
print("Sound not Detected")
else:
print("Sound detected")
os.system("curl -X POST https://maker.ifttt.com/trigger/SoundDetected/with/key/F0UrVFSWYTuvTzy-A7yT6")
print("playing music")
play_obj = wave_obj.play()
play_obj.wait_done()
print("song finished. Listening for more crying")
time.sleep(3)
if not GPIO.input(channel):
print("Sound continued")
os.system("curl -X POST https://maker.ifttt.com/trigger/SoundContinued/with/key/F0UrVFSWYTuvTzy-A7yT6")
else:
print("Sound has ceased")
os.system("curl -X POST https://maker.ifttt.com/trigger/BackToSleep/with/key/F0UrVFSWYTuvTzy-A7yT6")
def detectMovement(channel):
if GPIO.input(channel):
print("Movement Detected:")
time.sleep(5)
os.system("curl -X POST https://maker.ifttt.com/trigger/MovementDetected/with/key/F0UrVFSWYTuvTzy-A7yT6")
time.sleep(5)
else:
print("Movement not Detected")
while True:
detectSound(soundChannel)
detectMovement(movementChannel)
time.sleep(1)