Last active
October 13, 2015 20:04
-
-
Save dan-r/d5253c223b7d8d32357d to your computer and use it in GitHub Desktop.
Raspberry Pi Buzzer Alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time, sys | |
from RPi import GPIO | |
PIN = 18 | |
#0.001 ish is good | |
BUZZER_DELAY = float(sys.argv[1]) | |
REPEAT = int(sys.argv[2]) | |
try: | |
EXTRA = sys.argv[3] | |
except IndexError: | |
EXTRA = 0 | |
BUZZER_REPETITIONS = int((200 / BUZZER_DELAY)/(1000+int(EXTRA))) | |
print("Playing "+str(REPEAT)+" times at "+str(BUZZER_REPETITIONS)+" repetitions and a "+str(BUZZER_DELAY)+" second delay") | |
PAUSE_TIME = 0.3 | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(PIN, GPIO.OUT) | |
for i in range(REPEAT): | |
for _ in xrange(BUZZER_REPETITIONS): | |
for value in [True, False]: | |
GPIO.output(PIN, value) | |
time.sleep(BUZZER_DELAY) | |
time.sleep(PAUSE_TIME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment