Last active
June 12, 2019 13:40
-
-
Save Xevion/af874f27d78965cca97f1625b3d4987a to your computer and use it in GitHub Desktop.
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 RPi.GPIO as GPIO | |
import time | |
buzzerpin = 4 # pin the PWM Signal will run on, separate from GND / VCC | |
start_epoch = time.time() | |
# Sets up the GPIO and PWM frequency stuff | |
def setup(): | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setwarnings(False) | |
GPIO.setup(buzzerpin, GPIO.OUT) | |
global Buzzer, allocated_time | |
Buzzer = GPIO.PWM(buzzerpin, 500) # PWM on buzzerpin pin, initial 500 frequency | |
Buzzer.start(50) # drop out | |
allocated_time = 999 # Allocated time, while not erroring, the script will run for | |
# Cleanup function | |
def destroy(): | |
Buzzer.stop() | |
GPIO.cleanup() | |
# This loops whilst we're under the allocated time | |
def loop(): | |
# Buzzer.ChangeFrequency() | |
pass | |
# Returns true if we've passed the allocated time | |
def past(): | |
cur = time.time() | |
dif = cur - start_epoch | |
if dif >= allocated_time: | |
return True | |
return False | |
if __name__ == '__main__': | |
try: | |
setup() | |
while not past(): | |
loop() | |
except: | |
raise | |
finally: | |
destroy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment