Skip to content
Snippets Groups Projects
Commit 72c924ac authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Make buzzer global

parent 6ce30265
No related branches found
No related tags found
No related merge requests found
...@@ -107,6 +107,7 @@ LEDS = neopixel_spi.NeoPixel_SPI(board.SPI(), 10) ...@@ -107,6 +107,7 @@ LEDS = neopixel_spi.NeoPixel_SPI(board.SPI(), 10)
buzzer_pin = 18 buzzer_pin = 18
GPIO.setup(buzzer_pin, GPIO.OUT) GPIO.setup(buzzer_pin, GPIO.OUT)
BUZZER = GPIO.PWM(buzzer_pin, 440) # Set frequency to 1 Khz
# from input-event-codes.h # from input-event-codes.h
# type can be EV_SYN, EV_KEY or EV_MSC # type can be EV_SYN, EV_KEY or EV_MSC
...@@ -180,31 +181,29 @@ def dispatch_buzzer(state, config): ...@@ -180,31 +181,29 @@ def dispatch_buzzer(state, config):
buzzer_thread.start() buzzer_thread.start()
def set_buzzer(state, config): def set_buzzer(state, config):
global buzzer_pin global BUZZER
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz
state = str(state).strip().lower() state = str(state).strip().lower()
if state in ["startup", "ready"]: if state in ["startup", "ready"]:
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz
for i, note in enumerate(config["buzzer"]["startup_notes"]): for i, note in enumerate(config["buzzer"]["startup_notes"]):
buzzer.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz BUZZER.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10 BUZZER.start(50) # Set dutycycle to 10
time.sleep(repeat(config["buzzer"]["startup_note_lengths"], i)) time.sleep(repeat(config["buzzer"]["startup_note_lengths"], i))
buzzer.stop() BUZZER.stop()
time.sleep(repeat(config["buzzer"]["startup_note_stop_lengths"], i)) time.sleep(repeat(config["buzzer"]["startup_note_stop_lengths"], i))
elif state in ["success"]: elif state in ["success"]:
for i, note in enumerate(config["buzzer"]["success_notes"]): for i, note in enumerate(config["buzzer"]["success_notes"]):
buzzer.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz BUZZER.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10 BUZZER.start(50) # Set dutycycle to 10
time.sleep(repeat(config["buzzer"]["success_note_lengths"], i)) time.sleep(repeat(config["buzzer"]["success_note_lengths"], i))
buzzer.stop() BUZZER.stop()
time.sleep(repeat(config["buzzer"]["success_note_stop_lengths"], i)) time.sleep(repeat(config["buzzer"]["success_note_stop_lengths"], i))
elif state in ["failure"]: elif state in ["failure"]:
for i, note in enumerate(config["buzzer"]["failure_notes"]): for i, note in enumerate(config["buzzer"]["failure_notes"]):
buzzer.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz BUZZER.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10 BUZZER.start(50) # Set dutycycle to 10
time.sleep(repeat(config["buzzer"]["failure_note_lengths"], i)) time.sleep(repeat(config["buzzer"]["failure_note_lengths"], i))
buzzer.stop() BUZZER.stop()
time.sleep(repeat(config["buzzer"]["failure_note_stop_lengths"], i)) time.sleep(repeat(config["buzzer"]["failure_note_stop_lengths"], i))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment