Orangutan plays ring tones!

Some time ago I posted routines to play music using the Orangutan’s buzzer. The Pololu engineers have implemented similar routines for the X-2 controller, but all of these implementations suffer from the drawback that you have to somehow come up with the notes to play! For those not so musically inclined, this is not easy.

Monophonic RTTTL ring tones come to the rescue and they are available on lots of websites, free for the download. I’ve implemented two different routines. They both use timers 0 and 1 and will work on the atmega168. With a little effort, they will work on the atmega8 as well.

Ringtone_long.c was inspired by (and draws heavily from) code posted for the PIC processor by Craig Peacock at BeyondLogic beyondlogic.org/pic/ringtones.htm

Ringtone_long.c decodes a monophonic RTTTL string (read about Ring Tone Text Transfer Language at the website above) and calls a subroutine to play the tune, using timers 0 and 1 as a source of beat and frequency information. Read Craig’s excellent description of how the program works at the link above. You may download my version of the program from here: uoxray.uoregon.edu/orangutan/ringtone_long.c

Example tune array for ringtone_long.c (note the compiler-generated string concatemers):

// AxelF
	const unsigned char static Melody[] =  
        defaultoctave = 5;
        defaultduration = 4;
        beat_speed = 80;

Ringtone_short.c is much more compact and takes advantage of the “Tune Wizard” that is part of the PICAXE programming editor, free for the download at rev-ed.co.uk/picaxe/ Also download “manual 2” under picaxe data sheets and take a look at the tune command, which explains most things in detail. If you are musically inclined, you may be offended by the bizarre naming convention used for notes and octaves by Rev-Ed!

You must edit the byte array resulting from the Tune Wizard.
-Change the “$” into “0x” to define hex bytes.
-Add a tempo byte at the zeroth element of the array.
-If the array does not contain embedded zero bytes, add a zero byte at the END of the array to signify its end and use strlen() in the “for” loop to detect its end.
-If the array does contain an embedded zero byte (a 1/4 duration C note, “6th” octave), count the bytes in the array and change the “for” loop accordingly.

Better than the Tune Wizard, download about 1000 tune arrays from the Rev-Ed web site!
rev-ed.co.uk/picaxe/ (click on software tab and scroll down the page).

Example tune array for ringtone_short.c:

    // Godfather
    char tune_array[]=

Download ringtone_short.c at uoxray.uoregon.edu/orangutan … ne_short.c

Let me know if any problems arise.

1 Like