Name:
tune
Syntax:

TUNE pin, speed, (note, note, note...)  

TUNE pin, speed, LED_mask, (note, note, note...) (M2 parts only)

TUNE LED_option, speed, (note, note, note...) (8 pin only)

pin - is a variable/constant which specifies the i/o pin to use (not available on 8 pin devices, which are fixed to output 2).

speed - is a variable/constant (1-15) which specifies the tempo of the tune.

notes - are the actual tune data generated by the Tune Wizard.

LED_mask - (M2 parts only) is a variable/constant which specifies if other PICAXE outputs (on the same port as the piezo) flash at the same time as the tune is being played. For example use %00000011 to flash output 0 and 1.

LED_option - (08M/08M2 only) is a variable/constant (0 -3) which specifies if other 8 pin PICAXE outputs flash at the same time as the tune is being played.

0 - No outputs
1 - Output 0 flashes on and off
2 - Output 4 flashes on and off
3 - Output 0 and 4
Description:

The tune command allows musical 'tunes' to be played. Playing music on a microcontroller with limited memory will never have the quality of commercial playback devices, but the tune command performs remarkably well. Music can be played on economical piezo sounders (as found in musical birthday cards) or on better quality speakers.

Most users will use the 'Tune Wizard' to automatically generate the tune command, by either manually sequentially entering notes or by importing a mobile phone ring tone.

All tunes play on a piezo sounder or speaker, connected to the output pin (must be output 2 (leg 5) of the 8 pin devices). On all 8 pin and all M2 parts other outputs can be enabled to cause them to 'flash' in time to the music. The LEDs 'toggle' on/off at the end of every note.

PICAXE Tune Wizard

Looking for RTTTL ringtones? - see here

The Tune Wizard allows musical tunes to be created for the PICAXE. Tunes can be entered manually using the drop-down boxes if desired, but most users will prefer to automatically import a mobile phone monophonic ringtone. These ringtones are widely available on the internet in RTTTL format (used on older Nokia phones). Note the PICAXE can only play one note at a time (monophonic), and so cannot use multiple note (polyphonic) ringtones.

To start the Tune Wizard click the PICAXE>Wizard>Tune Wizard menu. The easiest way to import a ringtone from the internet is to find the tune on a web page.

Highlight the RTTTL version of the ringtone in the web browser and then click Edit>Copy.

Move back to the Tune Wizard and then click Edit>Paste Ringtone.

To import a ringtone from a saved text file, click File>Import Ringtone. Once the tune has been generated, select whether you want outputs to flash as the tune plays. The tune can then be tested on the computer by clicking the 'Play' menu (if your computer is fitted with soundcard and speakers). The tune played will give a rough idea of how the tune will sound on the PICAXE, but will differ slightly due to the different ways that the computer and PICAXE generate and playback sounds. On older computers the tune generation may take a couple of seconds as generating the tune is very memory intensive.

Once your tune is complete click the 'Copy' button to copy the tune command to the Windows clipboard. The tune can then be pasted into your main program.

Ring Tone Tips & Tricks:

1. After generating the tune, try adjusting the tempo by increasing or decreasing the speed value by 1 and listening to which 'speed' sounds best.
2. If your ringtone does not import, make sure the song title at the start of the line is less than 50 characters long and that all the text is saved on a single line.
3. Ringtones that contain the instruction 'd=16' after the description, or that contain many notes starting with 16 or 32 (the odd one or two doesn't matter) will not play correctly at normal speed on the PICAXE. However they may sound better if you double the PICAXE processor speed by using a 'setfreq m8' command before the tune command.
4. The PICAXE import filters 'round-down' dotted notes (notes ending with '.'). You may wish to change these notes into longer notes after importing.

 

Applies To:
All (except 08, 18, 18A, 18X, 28, 28A, 28X, 40X)
See Also:
Related Create:
Share:
Print:

Submit Your Own Code!

You must be logged in to submit code examples. Login now.

Comments

  • Login to leave a comment.