Merge pull request #153 from lovyan03/Speaker

Update: Speaker works even if you forget "M5.Speaker.begin()"
This commit is contained in:
EeeeBin
2019-04-27 15:10:08 +08:00
committed by GitHub
2 changed files with 7 additions and 1 deletions
+6 -1
View File
@@ -2,20 +2,24 @@
SPEAKER::SPEAKER(void) {
_volume = 8;
_begun = false;
}
void SPEAKER::begin() {
_begun = true;
ledcSetup(TONE_PIN_CHANNEL, 0, 13);
ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL);
// digitalWrite(SPEAKER_PIN, 0);
setBeep(1000, 100);
}
void SPEAKER::end() {
mute();
ledcDetachPin(SPEAKER_PIN);
_begun = false;
}
void SPEAKER::tone(uint16_t frequency) {
if(!_begun) begin();
ledcWriteTone(TONE_PIN_CHANNEL, frequency);
}
@@ -26,6 +30,7 @@ void SPEAKER::tone(uint16_t frequency, uint32_t duration) {
}
void SPEAKER::beep() {
if(!_begun) begin();
tone(_beep_freq, _beep_duration);
}
+1
View File
@@ -35,6 +35,7 @@
uint8_t _volume;
uint16_t _beep_duration;
uint16_t _beep_freq;
bool _begun;
bool speaker_on;
};
#endif