Skip to content

Commit 9a8679e

Browse files
use native implementation
1 parent 855bbb4 commit 9a8679e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

KY006_Buzzer_ESP32/KY006_Buzzer_ESP32.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ KY006_Buzzer_ESP32::KY006_Buzzer_ESP32(int buzzer_pin, int channel) {
1616
void KY006_Buzzer_ESP32::begin() {
1717
}
1818

19-
void KY006_Buzzer_ESP32::enable(unsigned int frequency, unsigned long duration) {
20-
// stop sound first
21-
disable();
19+
void KY006_Buzzer_ESP32::enable(note_t frequency, unsigned long duration) {
20+
ledcAttachPin(_buzzerPin, _channel);
21+
ledcWriteNote(_channel, frequency, duration);
22+
delay(duration);
2223

23-
// start sound
24-
tone(_buzzerPin, frequency, duration, _channel);
24+
disable();
2525
}
2626

2727
void KY006_Buzzer_ESP32::disable() {
28-
noTone(_buzzerPin, _channel);
28+
ledcDetachPin(_buzzerPin);
2929
}

KY006_Buzzer_ESP32/KY006_Buzzer_ESP32.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#define KY006_Buzzer_ESP32_h
99

1010
#include <Arduino.h>
11-
#include <Tone32.h>
1211

1312
class KY006_Buzzer_ESP32
1413
{
@@ -18,7 +17,7 @@ class KY006_Buzzer_ESP32
1817
int channel = 0
1918
);
2019
void begin();
21-
void enable(unsigned int frequency = 1000, unsigned long duration = 100);
20+
void enable(note_t frequency, unsigned long duration = 5);
2221
void disable();
2322

2423
private:

0 commit comments

Comments
 (0)