User Manual

Reference
C++ and Arduino methods are shown in red.
C functions are shown in green.
static void OrangutanBuzzer::playFrequency(unsigned int frequency, unsigned int duration, unsigned
char volume)
void play_frequency(unsigned int freq, unsigned int duration, unsigned char volume)
This method will play the specified frequency (in Hz or 0.1 Hz) for the specified duration (in ms). The
frequency argument must be between 40 Hz and 10 kHz. If the most significant bit of frequency is set, the
frequency played is the value of the lower 15 bits of frequency in units of 0.1 Hz. Therefore, you can play
a frequency of 44.5 Hz by using a frequency of (DIV_BY_10 | 445). If the most significant bit of frequency
is not set, the units for frequency are Hz. The volume argument controls the buzzer volume, with 15 being
the loudest and 0 being the quietest. A volume of 15 supplies the buzzer with a 50% duty cycle PWM at the
specified frequency. Lowering 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.
Example
// play a 6 kHz note for 250 ms at "half" volume
OrangutanBuzzer::playFrequency(6000, 250, 7);
// wait for buzzer to finish playing the note
while (OrangutanBuzzer::isPlaying());
// play a 44.5 Hz note for 1 s at full volume
OrangutanBuzzer::playFrequency(DIV_BY_10 | 445, 1000, 15);
// play a 6 kHz note for 250 ms at half volume
play_frequency(6000, 250, 7);
// wait for buzzer to finish playing the note
while (is_playing());
// play a 44.5 Hz note for 1 s at full volume
play_frequency(DIV_BY_10 | 445, 1000, 15);
Caution: frequency × duration/1000 must be no greater than 0xFFFF (65535). This means you
can’t use a max duration of 65535 ms for frequencies greater than 1 kHz. For example, the
maximum duration you can use for a frequency of 10 kHz is 6553 ms. If you use a duration
longer than this, you will produce an integer overflow that can result in unexpected behavior.
static void OrangutanBuzzer::playNote(unsigned char note, unsigned int duration, unsigned char volume)
void play_note(unsigned char note, unsigned int duration, unsigned char volume);
This method will play the specified note for the specified duration (in ms). The note argument is an
enumeration for the notes of the equal tempered scale (ETS). See the Note Macros section below for more
information. The volume argument controls the buzzer volume, with 15 being the loudest and 0 being the
quietest. A volume of 15 supplies the buzzer with a 50% duty cycle PWM at the specified frequency. Lowering
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
3. Orangutan Buzzer: Beeps and Music Page 14 of 65