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

Use propper midi to hertz formula

parent 6a6ed4cb
Branches
No related tags found
No related merge requests found
...@@ -181,34 +181,37 @@ def dispatch_buzzer(state, config): ...@@ -181,34 +181,37 @@ def dispatch_buzzer(state, config):
def set_buzzer(state, config): def set_buzzer(state, config):
global buzzer_pin global buzzer_pin
f = 8.175799
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz 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 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((1+note)*0.083333333*f) # 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((1+note)*0.083333333*f) # 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((1+note)*0.083333333*f) # 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))
def midinumber_to_hertz(number) -> float:
return 440 * 2**(number-69)/12
def process_request(output_queue, config=None, logger=None): def process_request(output_queue, config=None, logger=None):
""" """
Process a event from the output queue. Process a event from the output queue.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment