Skip to content

Commit

Permalink
Compatible with Arduino 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyu-Zhao authored Aug 23, 2024
1 parent ecf5030 commit 810fb42
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/utility/Speaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ SPEAKER::SPEAKER(void) {

void SPEAKER::begin() {
_begun = true;
ledcAttach(TONE_PIN_CHANNEL, 0, 13);
#if ESP_IDF_VERSION_MAJOR <= 4
ledcSetup(TONE_PIN_CHANNEL, 0, 13);
ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL);
#elif ESP_IDF_VERSION_MAJOR > 4
ledcAttach(SPEAKER_PIN, 0, 13);
#endif
setBeep(4000, 100);
}

void SPEAKER::end() {
mute();
#if ESP_IDF_VERSION_MAJOR <= 4
ledcDetachPin(SPEAKER_PIN);
#elif ESP_IDF_VERSION_MAJOR > 4
ledcDetach(SPEAKER_PIN);
#endif
_begun = false;
}

Expand Down Expand Up @@ -74,5 +83,9 @@ void SPEAKER::playMusic(const uint8_t* music_data, uint16_t sample_rate) {
delay(2);
}
}
ledcAttach(TONE_PIN_CHANNEL, 0, 13);
#if ESP_IDF_VERSION_MAJOR <= 4
ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL);
#elif ESP_IDF_VERSION_MAJOR > 4
ledcAttach(SPEAKER_PIN, 0, 13);
#endif
}

0 comments on commit 810fb42

Please sign in to comment.