Play tune,... ?

Hi,
Trying to use play-command on a 08M2, but became a little confused.
Manual 2 says:
PLAY pin, tune (all non-8 pin parts)
PLAY pin, tune, LED_mask (M2 parts only)
PLAY tune, LED_option (8 pin devices only)

Using a 08M, alt. 3 obviously applies, and it works. Not so obvious with 08M2, however, as both alt. 2 and 3 applies. But alt. 2 gives an error msg from the compiler, which leaves me with alt 3. However, 'play b1,0' creates this err. msg:
Error: use song number 0 - 3 only
So I try 'play 1,0' ... and Bingo: Jingle bells, - no diode blinking. The problem seems to be that the compiler rejects tune as a variable, in both PE5 and 6. Is this a bug?
 

hippy

Ex-Staff (retired)
Is this a bug?
" A feature".

You can use ...

Code:
[color=Navy]#Macro [/color][color=Black]PlayVar[/color][color=Blue]( [/color][color=Black]tuneNumber, leds [/color][color=Blue])
  Select Case [/color][color=Black]tuneNumber
     [/color][color=Blue]Case [/color][color=Navy]0 [/color][color=Black]: [/color][color=Blue]Play [/color][color=Navy]0[/color][color=Black], leds
     [/color][color=Blue]Case [/color][color=Navy]1 [/color][color=Black]: [/color][color=Blue]Play [/color][color=Navy]1[/color][color=Black], leds
     [/color][color=Blue]Case [/color][color=Navy]2 [/color][color=Black]: [/color][color=Blue]Play [/color][color=Navy]2[/color][color=Black], leds
     [/color][color=Blue]Case [/color][color=Navy]3 [/color][color=Black]: [/color][color=Blue]Play [/color][color=Navy]3[/color][color=Black], leds
  [/color][color=Blue]End Select[/color]
[color=Navy]#EndMacro[/color]

[color=Black]PlayVar[/color][color=Blue]( [/color][color=Purple]b0[/color][color=Black], [/color][color=Navy]0 [/color][color=Blue])[/color]
You can use the SELECT-CASE in-line rather than wrap it in a macro if you prefer.
 
Thanks for the answer, and for the workaround, in fact that is what I did using if-then-elseif, but it takes much space in a 08M2LE ..
However, the Manual 2 says, "Tune is a variable/constant (0 - 3) which specifies which tune to play"... So this has changed. OK.
 

hippy

Ex-Staff (retired)
Possibly an error or typo in the manual or perhaps something which has changed as the PICAXE range has evolved.

If you are using the commands/macro multiple times you can save memory by placing the code in a subroutine.
 
Top