From 4b55ee14efcbd05d8c2162db1f347f465da73b87 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sat, 12 Mar 2016 17:42:30 +0200 Subject: [PATCH] Allow indefinite duration for `tone()` Bugfix: the `duration` parameter should be optional, per [`tone()`](https://www.arduino.cc/en/Reference/Tone) docs. --- cores/esp8266/Tone.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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);