3.b.2. Command 160: Play Frequency

Effect: Plays the desired frequency immediately. Allowed frequencies are those greater than 40 Hz and less than 10 kHz. The frequency is a 15-bit value specified in Hz. Duration a 16-bit value specified in ms.

If the buzzer is currently playing when this command is received, this command will take precedence and overwrite the current buzzer action. For example, if a melody was playing, the note specified by this command will interrupt the melody and after the note is through the melody will not continue. As such, if you wish to stream a sequence of notes to the mega168 using this command, you must time the issuance of the commands on the mega644 so that each note doesn’t just overwrite the previous. This command will not queue up the notes if called repeatedly.

It is important to note that there is a restriction on the duration of any notes whose frequencies are greater than 1 kHz. The product of the duration (in ms) and the frequency (in kHz) must be no greater than 0xFFFF (65,535). If you attempt to play a frequency of 10 kHz, for example, the maximum duration you can specify is 6553 ms. If you specify a longer duration there will be an integer overflow and the resulting duration of the note will not be what you specified. If you wish to play a 10 kHz frequency for longer than 6.5 seconds, you can accomplish this by stringing together multiple play-frequency commands.

Values sent: frequency (15 bits), duration (16 bits)

command byte = 160 | (MSB data byte 4 << 2) | (MSB data byte 3 << 1) | MSB data byte 2

data byte 1 = most significant byte of frequency word (MSB always 0)

data byte 2 = least significant byte of frequency word (missing MSB)

data byte 3 = most significant byte of duration word (missing MSB)

data byte 4 = least significant byte of duration word (missing MSB)

Related Products

Orangutan X2 with VNH3
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors