Bugfix on Piezo Music Example (Circuit 06)

Updated: From the friendly people at Oomlout.com who make the ARDX:

Thanks for explaining the issue to us, we’ll get it marked to be fixed in the next update run.

Going through the ARDX tutorials, the piezo music one was nice and simple. However when I listened to the output, there was something off. It wasn’t keeping the beat. You can hear it below at the end of the 7th note (Twinkle twinkle little star …).

Twitch. I have some musical kids books that have this same bug. Twitch every time.

The original note logic goes like this:

  • note_beats[i]: how many beats to play the ith note
  • beat_time: how long for each beat
  • pause_time: short pause after each note so notes are audibly separated

So complete_note_time = (note_beats[i] * beat_time) + pause_time

This is fine when all notes have the same number of beats. However when each note is held for various beat counts, the pause time does not get extended so each note is no longer a full beat. Let’s do the easiest fix (although not the best):

Now complete_note_time  = (note_beats[i] * beat_time) + (note_beats[i] * pause_time)

No more twitch:

Here is the code with the fix noted on the pause line.

Leave a Reply

Your email address will not be published. Required fields are marked *