diff --git a/cores/esp8266/Tone.cpp b/cores/esp8266/Tone.cpp index 9d262e3bb..19c8817c9 100644 --- a/cores/esp8266/Tone.cpp +++ b/cores/esp8266/Tone.cpp @@ -114,10 +114,14 @@ void noTone(uint8_t _pin) { } void t1IntHandler() { - if (toggle_counts[T1INDEX] > 0){ + if (toggle_counts[T1INDEX] != 0){ // toggle the pin digitalWrite(tone_pins[T1INDEX], toggle_counts[T1INDEX] % 2); toggle_counts[T1INDEX]--; + // handle the case of indefinite duration + if (toggle_counts[T1INDEX] < -2){ + toggle_counts[T1INDEX] = -1; + } }else{ disableTimer(T1INDEX); digitalWrite(tone_pins[T1INDEX], LOW);