Skip to content

Commit 4b55ee1

Browse files
committed
Allow indefinite duration for tone()
Bugfix: the `duration` parameter should be optional, per [`tone()`](https://www.arduino.cc/en/Reference/Tone) docs.
1 parent 5cec334 commit 4b55ee1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cores/esp8266/Tone.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@ void noTone(uint8_t _pin) {
114114
}
115115

116116
void t1IntHandler() {
117-
if (toggle_counts[T1INDEX] > 0){
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)