From 57e57a07bb05ffb1ccb8ace1cc0b3489686d21c7 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Fri, 14 May 2021 20:51:01 +0200 Subject: [PATCH] Buzzer freq fix --- main.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 25e22b7..855a1b8 100644 --- a/main.cpp +++ b/main.cpp @@ -370,11 +370,15 @@ void updateMotors() //create square wave for buzzer buzzer.timer++; - if (buzzer.state.freq != 0 && (buzzer.timer / 1000) % (buzzer.state.pattern + 1) == 0) { - if (buzzer.timer % (buzzer.state.freq/2) == 0) { - HAL_GPIO_TogglePin(BUZZER_PORT, BUZZER_PIN); - } - } else { + if (buzzer.state.freq != 0 && (buzzer.timer / 1000) % (buzzer.state.pattern + 1) == 0) + { + if (buzzer.timer % buzzer.state.freq == 0) + { + HAL_GPIO_TogglePin(BUZZER_PORT, BUZZER_PIN); + } + } + else + { HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, GPIO_PIN_RESET); }