Skip to content

Commit 9d4208e

Browse files
committed
Merge pull request #1760 from urish/patch-2
Allow indefinite duration for `tone()`
2 parents cf47b42 + 748f3f9 commit 9d4208e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cores/esp8266/Tone.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,15 @@ void noTone(uint8_t _pin) {
113113
digitalWrite(_pin, LOW);
114114
}
115115

116-
void t1IntHandler() {
117-
if (toggle_counts[T1INDEX] > 0){
116+
ICACHE_RAM_ATTR void t1IntHandler() {
117+
if (toggle_counts[T1INDEX] != 0){
118118
// toggle the pin
119119
digitalWrite(tone_pins[T1INDEX], toggle_counts[T1INDEX] % 2);
120120
toggle_counts[T1INDEX]--;
121+
// handle the case of indefinite duration
122+
if (toggle_counts[T1INDEX] < -2){
123+
toggle_counts[T1INDEX] = -1;
124+
}
121125
}else{
122126
disableTimer(T1INDEX);
123127
digitalWrite(tone_pins[T1INDEX], LOW);

0 commit comments

Comments
 (0)