How do I stop sounds on demand

piclt

Member
Tune command Plays for duration of tune
Play command plays for duration of tune
Sounds play for duration multiples of 10ms
If want them to play longer put command in loop. But how can I stop the sound without waiting until end of tune if I want it to stop immediately say an input pin changes state. The prog will wait till end of tune before reading next line of prog. ???
 

thelabwiz

Senior Member
From the manual's definition of "setint", it looks as though you can interrupt a tune. Note the portion between the "***".

A polled interrupt is a quicker way of reacting to a particular input combination.
It is the only type of interrupt available in the PICAXE system. The inputs port is
checked between execution of each command line in the program, ***betwen each
note of a tune command***, and continuously during any pause command. If the
particular inputs condition is true, a ‘gosub’ to the interrupt sub-procedure is
executed immediately. When the sub-procedure has been carried out, program
execution continues from the main program.

John
 

piclt

Member
Thanks for reply, Setint is probably the right idea, but it is not real tunes that I want to play. I want to play a continuous sound (using tune command as it gives a musical note), for a few seconds and change to a different sound when an input or several inputs change. If I play several short notes or short notes in a loop ( all same pitch) I get clicks between each note, so I play long note but need to stop it and change before the note finishes playing. I will test out the interupt gosub and see but I think it may wait until end of long note before interupting, also after gosub returns may continue to play remainder of note. Thanks for your help and ideas
 

piclt

Member
Got around it another way.
Used pulsout in a loop, checked state of pins each time through loop and if changed then goto another label with a loop and a different pulsout time so gives a different sound and the sounds is continuous until a pin changes state.
 
Top