Orangutan plays music!

At first I thought the above was a great idea but after trying to code it, I realized that in CTC mode, OCR2A resets the timer. OCR2B interrupts never occur if OCR2B>OCR2A. Also, interrupts occur at a variable frequency, so it seems you can’t have a steady clock tick out of the same timer for other timing purposes.

The simplest approach is to use two timers to implement an “all-interrupt” music player. I’ve done so, using timer 0 to provide steady 1 millisecond ticks, and play the tune, while timer 2 is used for frequency generation. I also changed the note scale so that it accurately corresponds to the International Tempered Scale.

This frees up the bot to do a victory dance while playing an appropriate tune.

New buzzer code, which plays the first 28 bars of “The Sorcerer’s Apprentice” can be downloaded at:
uoxray.uoregon.edu/orangutan/buzzer_tunes2.c

If someone can figure out how to use one timer to generate both variable frequencies and steady clock ticks, let us know!

Onward, Jim

PS To generate the tune array for the Sorcerer’s Apprentice, I downloaded a MIDI file for a flute score from borg.com/~jglatt/
to decode the MIDI file and create a human-readable text file. I transposed the score up one octave for the Orangutan. The note timings were a bit tricky, but otherwise, easy as 3.14159.