diff options
| author | EnricoGuccii <partyka.003@proton.me> | 2025-12-22 23:30:13 +0100 |
|---|---|---|
| committer | EnricoGuccii <partyka.003@proton.me> | 2025-12-22 23:30:13 +0100 |
| commit | 967500ab8abefa6700941d589979176677ab0d72 (patch) | |
| tree | 44e818d80accb785b467017dc2642e2af67cdfb7 /lib/buzzer | |
| parent | 86ba591615dde725833b2a024c79f9611326d8eb (diff) | |
yyy
Diffstat (limited to 'lib/buzzer')
| -rw-r--r-- | lib/buzzer/buzzer.cpp | 72 | ||||
| -rw-r--r-- | lib/buzzer/buzzer.h | 30 |
2 files changed, 46 insertions, 56 deletions
diff --git a/lib/buzzer/buzzer.cpp b/lib/buzzer/buzzer.cpp index df67ac7..089f814 100644 --- a/lib/buzzer/buzzer.cpp +++ b/lib/buzzer/buzzer.cpp @@ -1,41 +1,31 @@ -#include <Arduino.h> -#include "settings.h" -#include "buzzer.h" - -#define BUZZER_CHANNEL 3 -#define BUZZER_RESOLUTION 8 -#define BUZZER_FREQ 2000 - -BUZZER::BUZZER() -{ -} - -void BUZZER::init() -{ - ledcSetup(BUZZER_CHANNEL, BUZZER_FREQ, BUZZER_RESOLUTION); - ledcAttachPin(BUZZER_PIN, BUZZER_CHANNEL); -} - -void BUZZER::playTone(uint16_t frequency, uint32_t duration) -{ - ledcWriteTone(BUZZER_CHANNEL, frequency); - if (duration > 0) - { - delay(duration); - stop(); - } -} - -void BUZZER::playMelody(const uint16_t melody[][2], size_t length) -{ - for (size_t i = 0; i < length; i++) - { - playTone(melody[i][0], melody[i][1]); - delay(50); - } -} - -void BUZZER::stop() -{ - ledcWriteTone(BUZZER_CHANNEL, 0); -}
\ No newline at end of file +#include "buzzer.h"
+#include "settings.h"
+#include <Arduino.h>
+
+#define BUZZER_CHANNEL 3
+#define BUZZER_RESOLUTION 8
+#define BUZZER_FREQ 2000
+
+BUZZER::BUZZER() {}
+
+void BUZZER::init() {
+ ledcSetup(BUZZER_CHANNEL, BUZZER_FREQ, BUZZER_RESOLUTION);
+ ledcAttachPin(BUZZER_PIN, BUZZER_CHANNEL);
+}
+
+void BUZZER::playTone(uint16_t frequency, uint32_t duration) {
+ ledcWriteTone(BUZZER_CHANNEL, frequency);
+ if (duration > 0) {
+ delay(duration);
+ stop();
+ }
+}
+
+void BUZZER::playMelody(const uint16_t melody[][2], size_t length) {
+ for (size_t i = 0; i < length; i++) {
+ playTone(melody[i][0], melody[i][1]);
+ delay(50);
+ }
+}
+
+void BUZZER::stop() { ledcWriteTone(BUZZER_CHANNEL, 0); }
diff --git a/lib/buzzer/buzzer.h b/lib/buzzer/buzzer.h index 717a79c..af2ae9d 100644 --- a/lib/buzzer/buzzer.h +++ b/lib/buzzer/buzzer.h @@ -1,15 +1,15 @@ -#include <Arduino.h> -#include "settings.h" - -#pragma once - -class BUZZER -{ -public: - BUZZER(); - - void init(); - void playTone(uint16_t frequency, uint32_t duration = 0); - void stop(); - void playMelody(const uint16_t melody[][2], size_t length); -}; +#include <Arduino.h>
+#include "settings.h"
+
+#pragma once
+
+class BUZZER
+{
+public:
+ BUZZER();
+
+ void init();
+ void playTone(uint16_t frequency, uint32_t duration = 0);
+ void stop();
+ void playMelody(const uint16_t melody[][2], size_t length);
+};
|