forked from scaidermern/piCamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_buzzer.py
executable file
·38 lines (34 loc) · 941 Bytes
/
test_buzzer.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import json
import signal
import sys
import time
# always cleanup GPIO on strg-c or kill
# and disable buzzer
def signalHandler(signal, frame):
print('buzzer: off')
GPIO.output(gpio, 0)
GPIO.cleanup()
sys.exit(0)
def playSequence(sequence, duration):
for i in sequence:
if i == '1':
GPIO.output(gpio, 1)
print('buzzer: on')
elif i == '0':
GPIO.output(gpio, 0)
print('buzzer: off')
else:
print('unknown pattern in sequence: %s', i)
time.sleep(duration)
config = json.load(open('config.json', 'r'))
gpio = config['buzzer']['gpio']
duration = config['buzzer']['duration']
sequence = config['buzzer']['seq_motion']
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio, GPIO.OUT)
signal.signal(signal.SIGINT, signalHandler)
while True:
playSequence(sequence, duration)