User Manual
volume by one halves the duty cycle (so 14 gives a 25% duty cycle, 13 gives a 12.5% duty cycle, etc). The
volume control is somewhat crude and should be thought of as a bonus feature.
This function plays the note in the background while your program continues to execute. If you call another
buzzer function while the note is playing, the new function call will overwrite the previous and take control of
the buzzer. If you want to string notes together, you should either use the play() function or put an appropriate
delay after you start a note playing. You can use the is_playing() function to figure out when the buzzer is
through playing its note or melody.
Note Macros
To make it easier for you to specify notes in your code, this library defines the following macros:
// x will determine the octave of the note
#define C( x ) ( 0 + x*12 )
#define C_SHARP( x ) ( 1 + x*12 )
#define D_FLAT( x ) ( 1 + x*12 )
#define D( x ) ( 2 + x*12 )
#define D_SHARP( x ) ( 3 + x*12 )
#define E_FLAT( x ) ( 3 + x*12 )
#define E( x ) ( 4 + x*12 )
#define F( x ) ( 5 + x*12 )
#define F_SHARP( x ) ( 6 + x*12 )
#define G_FLAT( x ) ( 6 + x*12 )
#define G( x ) ( 7 + x*12 )
#define G_SHARP( x ) ( 8 + x*12 )
#define A_FLAT( x ) ( 8 + x*12 )
#define A( x ) ( 9 + x*12 )
#define A_SHARP( x ) ( 10 + x*12 )
#define B_FLAT( x ) ( 10 + x*12 )
#define B( x ) ( 11 + x*12 )
// 255 (silences buzzer for the note duration)
#define SILENT_NOTE 0xFF
// e.g. frequency = 445 | DIV_BY_10
// gives a frequency of 44.5 Hz
#define DIV_BY_10 (1 << 15)
static void OrangutanBuzzer::play(const char* sequence)
void play(const char* sequence)
This method plays the specified sequence of notes. If the play mode is PLAY_AUTOMATIC (default), the
sequence of notes will play with no further action required by the user. If the play mode is PLAY_CHECK,
the user will need to call playCheck() in the main loop to initiate the playing of each new note in the sequence.
The play mode can be changed while the sequence is playing. The sequence syntax is modeled after the PLAY
commands in GW-BASIC, with just a few differences.
The notes are specified by the characters C, D, E, F, G, A, and B, and they are played by default as
“quarter notes” with a length of 500 ms. This corresponds to a tempo of 120 beats/min. Other durations can
be specified by putting a number immediately after the note. For example, C8 specifies C played as an eighth
note, with half the duration of a quarter note. The special note R plays a rest (no sound). The sequence parser
is case-insensitive and ignore spaces, which may be used to format your music nicely.
Various control characters alter the sound:
• ‘A’ – ‘G’: used to specify the notes that will be played
• ‘R’: used to specify a rest (no sound for the duration of the note)
• ‘>’ plays the next note one octave higher
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
3. Orangutan Buzzer: Beeps and Music Page 15 of 65