Skip to content

jgOhYeah/TunePlayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TunePlayer Arduino Lint Actions Status

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.

Quick links

This library is inspired (but not compatible with) the PICAXE tune command

This cppQueue library is required to be installed.

Getting started

See the simple example for this in one file.

Installation

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.

Hardware

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 the library

#include <TunePlayer.h>

Add the tune

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.
};

Create the required objects

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.

Set up to play

flashLoader.setTune(FucikEntryoftheGladiatorsPNO);
tune.begin(&flashLoader, &piezo);

Play

tune.play();

Regularly update

This needs to be called as often as possible while the tune is playing.

tune.update();

Other functionality

See the API reference.