-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintercom.py
50 lines (44 loc) · 1.24 KB
/
intercom.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
#!/usr/bin/python3
import RPi.GPIO as GPIO
import subprocess
import shlex
from time import sleep
def greeting():
command_line = 'aplay /home/pi/intercom/greeting.wav'
args = shlex.split(command_line)
subprocess.call(args)
def answer():
command_line = 'sudo arecord -D plughw:1 --duration=3 -f cd /home/pi/intercom/answer.wav'
args = shlex.split(command_line)
subprocess.call(args)
def pulsador():
if (GPIO.input(16)):
GPIO.output(11, 1)
GPIO.output(7, 1)
sleep(2)
greeting()
answer()
GPIO.output(11, 0)
GPIO.output(7, 0)
GPIO.output(13, 1)
sleep(2)
GPIO.output(13, 0)
if __name__ == '__main__':
try:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.IN)
GPIO.setwarnings(False)
GPIO.setup(7, GPIO.OUT, initial=0)
GPIO.setup(11, GPIO.OUT, initial=0)
GPIO.setup(13, GPIO.OUT, initial=0)
while True:
pulsador()
except KeyboardInterrupt:
GPIO.cleanup()
exit(0)
except Exception as e:
print("Error:")
print(e)
finally:
GPIO.cleanup()
exit(1)