An Arduino library to decode and play simple tunes.
Each note is stored as a 16 bit integer and the method of loading tunes and how each note is played is reconfigurable. The current anticipated method of tune playing revolves around a pwm square wave on a piezo siren or speaker.
This library is inspired (but not compatible with) the PICAXE tune command
This cppQueue library is required to be installed.
See the simple example for this in one file.
Search for TunePlayer in the Arduino library manager or download this repository and copy it to the libraries folder (for me, ~/Documents/Arduino/libraries/). If not installed already, the cppQueue library should be installed as well.
The simplest way is to connect a piezo buzzer / siren (e.g. smoke alarm) to the output pin (pin 9 in the examples). For makimum loudness, you will probably need a driver circuit and tune things to resonate.
#include <TunePlayer.h>
See the Musescore Plugin page for a fairly straightforward way to generate the tunes.
// Converted from 'FucikEntryoftheGladiatorsPNO' by TunePlayer Musescore plugin V1.6
const uint16_t FucikEntryoftheGladiatorsPNO[] PROGMEM = {
0xe118, // Tempo change to 280.0002 BPM
0x3a38,0x2a38,0x1a18,0x2a18,0x1a18,0xa18,0xb838,
// ...
0xf000 // End of tune. Stop playing.
};
FlashTuneLoader flashLoader; // Where the notes come from
#define PIEZO_PIN 9
ToneSound piezo(PIEZO_PIN); // What plays the notes
TunePlayer tune; // Coordinates everything and does things at the right times.
flashLoader.setTune(FucikEntryoftheGladiatorsPNO);
tune.begin(&flashLoader, &piezo);
tune.play();
This needs to be called as often as possible while the tune is playing.
tune.update();
See the API reference.