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
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). frequency 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.
volume controls the buzzer volume, with 15 being the loudest and 0 being the quietest.
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);
// wait for buzzer to finish playing the note
// (or just use a 1000 ms delay)
while (OrangutanBuzzer::isPlaying());
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). volume controls the buzzer volume,
with 15 being the loudest and 0 being the quietest. The note argument is an enumeration for the notes of the equal
tempered scale (ETS):
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 )
Pololu AVR Library Command Reference © 2001–2009 Pololu Corporation
4. Orangutan Buzzer: Beeps and Music Page 9 of 35










