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
// the first few measures of Bach's fugue in D-minor
OrangutanBuzzer::play("!T240 L8 a gafaeada c+adaeafa >aa>bac#ada c#adaeaf4");
static void playFromProgramSpace(const char* sequence)
void play_from_program_space(const char* sequence)
A version of play() that takes a pointer to program space instead of RAM. This is desirable since RAM is limited
and the string must be stored in program space anyway.
Example:
#include <avr/pgmspace.h>
const char melody[] PROGMEM = "!L16 V8 cdefgab>cbagfedc";
void someFunction()
{
OrangutanBuzzer::playFromProgramSpace(melody);
}
static void OrangutanBuzzer::playMode(unsigned char mode)
void play_mode(char mode)
This method lets you determine whether the notes of the play() sequence are played automatically in the
background or are driven by the playCheck() method. If mode is PLAY_AUTOMATIC, the sequence will play
automatically in the background, driven by the Timer1 overflow interrupt. The interrupt will take a considerable
amount of time to execute when it starts the next note in the sequence playing, so it is recommended that you do
not use automatic-play if you cannot tolerate being interrupted for more than a few microseconds. If mode is
PLAY_CHECK, you can control when the next note in the sequence is played by calling the playCheck() method
at acceptable points in your main loop. If your main loop has substantial delays, it is recommended that you use
automatic-play mode rather than play-check mode. Note that the play mode can be changed while the sequence is
being played. The mode is set to PLAY_AUTOMATIC by default.
static unsigned char OrangutanBuzzer::playCheck()
unsigned char play_check()
This method only needs to be called if you are in PLAY_CHECK mode. It checks to see whether it is time to start
another note in the sequence initiated by play(), and starts it if so. If it is not yet time to start the next note, this
method returns without doing anything. Call this as often as possible in your main loop to avoid delays between
notes in the sequence. This method returns 0 (false) if the melody to be played is complete, otherwise it returns 1
(true).
static unsigned char isPlaying()
unsigned char is_playing()
This method returns 1 (true) if the buzzer is currently playing a note/frequency. Otherwise, it returns 0 (false).
You can poll this method to determine when it’s time to play the next note in a sequence, or you can use it as the
argument to a delay loop to wait while the buzzer is busy.
static void OrangutanBuzzer::stopPlaying()
void stop_playing()
This method will immediately silence the buzzer and terminate any note/frequency/melody that is currently
playing.
Pololu AVR Library Command Reference © 2001–2009 Pololu Corporation
4. Orangutan Buzzer: Beeps and Music Page 11 of 35










