AVR Library Command Reference
Table Of Contents
- Pololu AVR Library Command Reference
- 1. Introduction
- 2. Timing and Delays
- Reference
- 3. Orangutan Analog-to-Digital Conversion
- Reference
- 4. Orangutan Buzzer: Beeps and Music
- Reference
- 5. Orangutan LCD
- Reference
- 6. Orangutan LEDs
- Reference
- 7. Orangutan Motor Control
- Reference
- 8. Orangutan Pushbuttons
- Reference
- 9. Orangutan Serial Port Communication
- Reference
- 10. Orangutan System Resources
- 11. QTR Reflectance Sensors
- Reference
- 12. 3pi Robot Functions
- 13. Wheel Encoders
- Reference
// 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
• ’<’ plays the next note one octave lower
• ’+’ or ’#’ after a note raises any note one half-step
• ’-’ after a note lowers any note one half-step
• ’.’ after a note “dots” it, increasing the length by 50%. Each additional dot adds half as much as the
previous dot, so that “A..” is 1.75 times the length of “A”.
• ‘O’ followed by a number sets the octave (default: O4).
• ‘T’ followed by a number sets the tempo in beats/min (default: T120).
• ‘L’ followed by a number sets the default note duration to the type specified by the number: 4 for quarter
notes, 8 for eighth notes, 16 for sixteenth notes, etc. (default: L4).
• ‘V’ followed by a number from 0-15 sets the music volume (default: V15).
• ‘MS’ sets all subsequent notes to play play staccato – each note is played for 1/2 of its allotted time,
followed by an equal period of silence.
• ‘ML’ sets all subsequent notes to play legato – each note is played for full length. This is the default
setting.
• ’!’ resets the octave, tempo, duration, volume, and staccato setting to their default values. These settings
persist from one play() to the next, which allows you to more conveniently break up your music into
reusable sections.
• ‘1’ – "2000": when immediately following a note, a number determines the duration of the note. For
example, C16 specifies C played as a sixteenth note (1/16th the length of a whole note).
Examples:
// play a C major scale up and back down:
OrangutanBuzzer::play("!L16 V8 cdefgab>cbagfedc");
Pololu AVR Library Command Reference © 2001–2009 Pololu Corporation
4. Orangutan Buzzer: Beeps and Music Page 10 of 35










