Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent divide by zero error causing tone() to crash #2780

Merged
merged 5 commits into from
Jan 17, 2017

Commits on Dec 20, 2016

  1. Prevent divide by zero error causing code to crash

    As per the issue at esp8266#2491, there is a divide by error issue resulting from the specification of 0 as the frequency. This does not appear to affect the AVR implementation, but it crashes on ESP8266s. I have merely removed the division if the frequency is zero, which appears to be giving the expected results (no tone), without any code crashes. 
    
    To test, simply load the toneMelody sketch included with the Arduino IDE (Examples -> 02. Digital -> toneMelody) and change the piezo to something else if you need to. On the Witty module used to test this, I could also tell by the wifi led blinking every time the code crashed as the ESP8266 immediately rebooted.
    pfeerick authored Dec 20, 2016
    Configuration menu
    Copy the full SHA
    7c3d21a View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2017

  1. Use noTone when frequency is zero

    When a frequency of zero is given to tone(), instead call noTone() and exit. Placed after some of the initialisation stuff to ensure the pin is mapped as a output, etc. Tested as functional against a Node MCU 1.0 board and the toneMelody example sketch, using GPIO5 (pin D1).
    pfeerick authored Jan 10, 2017
    Configuration menu
    Copy the full SHA
    d4aa9be View commit details
    Browse the repository at this point in the history
  2. Errant tab in formatting

    pfeerick authored Jan 10, 2017
    Configuration menu
    Copy the full SHA
    641faab View commit details
    Browse the repository at this point in the history
  3. Rest of tabs that crept in from web editor

    Defaulted to tabs and 8 indent :sigh:
    pfeerick authored Jan 10, 2017
    Configuration menu
    Copy the full SHA
    d5ccfcf View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6480da9 View commit details
    Browse the repository at this point in the history