diff --git a/cores/esp8266/Tone.cpp b/cores/esp8266/Tone.cpp index bcdd358a8..fb7837ee4 100644 --- a/cores/esp8266/Tone.cpp +++ b/cores/esp8266/Tone.cpp @@ -64,6 +64,13 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) { // Set the pinMode as OUTPUT pinMode(_pin, OUTPUT); + // Alternate handling of zero freqency to avoid divide by zero errors + if (frequency == 0) + { + noTone(_pin); + return; + } + // Calculate the toggle count if (duration > 0) { toggle_counts[_index] = 2 * frequency * duration / 1000;