Skip to content

tone() with a frequency of 0 will crash Oak #75

Description

@pfeerick

This bug originates from the ESP8266 Arduino core implementation, but I am also referencing it here as I will crosslink the two issues so it is easy to implement a solution once the best course of action is decided.

As per a discussion thread on the forum, an issue has been idenfied in the tone() function that caused the example sketch to fail. Whenever the tone command is issues with a frequency of 0, it will crash the sketch, and the Oak just freezes (on the pure ESP8266 core it instead reboots).

The workaround I have suggested for now at the sketch level for the example sketch is to use an if statement to catch a zero frequency call, and issue the noTone() command instead and then delay for the specified duration. In the example this happens as there is a series of notes specified in an array, and a '0' is used as a pause in the melody... with unexpected results on the ESP8266! 😢

i.e. Instead of

tone(3, melody[thisNote], noteDuration);

to use

if (melody[thisNote] == 0)
{
  noTone(3);
  delay(noteDuration);
}
else
{
  tone(3, melody[thisNote], noteDuration);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions