You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In "Play melody" page there are two code examples for producing tones on a passive piezo buzzer.
However, in the 1st example the user is instructed to use a "PWM pin" of the Arduino for producing the tone, which is pretty restricting. By going through the code I see that the tone is produced in software by turning that pin HIGH and LOW at predetermined time intervals; this can be done with a "non-PWM" pin, and to my opinion, more correctly so. After all, the used pin isn't used as a PWM out.
Correct me if I'm wrong.
The text was updated successfully, but these errors were encountered:
The link should be https://www.arduino.cc/en/Tutorial/PlayMelody .
In fact the first example doesn't need a PWM pin, while the second code (which uses analogWrite ) does. I believe that the pin was chosen that way to switch easily between the two examples; however the comments on the first example should be slightly changed.
Related to this, there appears to be an issue with tone() on the SAMD boards. When you play a tone of frequency <1, it freezes up. In the playMelody() example, for example, on a nano 33 Iot, it plays the first five notes of "shave and a haircut", then stops. If you change the sixth note, which is currently 0, to 1, then it plays the whole tune, "shave and a haircut, two bits".
I haven't tried to replicate this on the other architectures recently, but I know that it worked on the Uno as of version 1.8.9.
I seems that PlayMelody tutorial was removed completely from arduino.cc sometime after 2020-07-20. Since nothing remains to fix, I'll go ahead and close this.
In "Play melody" page there are two code examples for producing tones on a passive piezo buzzer.
However, in the 1st example the user is instructed to use a "PWM pin" of the Arduino for producing the tone, which is pretty restricting. By going through the code I see that the tone is produced in software by turning that pin HIGH and LOW at predetermined time intervals; this can be done with a "non-PWM" pin, and to my opinion, more correctly so. After all, the used pin isn't used as a PWM out.
Correct me if I'm wrong.
The text was updated successfully, but these errors were encountered: