Same pin interrupt help ?

1968neil

Senior Member
Hi Folk's,

Is it possible to do the following with an 08M2 ?

Press a button that goes to play a tune (tune command) and if the same button is pressed interrupt that tune and return to the start of the program ?

rough example

Code:
 'PICAXE-08M2
 'No Data 

Symbol  press_Button = PinC.4




Main:
	pause 10
	if press_Button=1 then PlayTune          
	pause 10
	goto main                     'loop back to main




PlayTune:

; interrupt this routine and return to main ?

tune 0, 7, ($40,$48,$43,$4A,$50,$58,$53,$5A,$50)

Goto Main
 

Technical

Technical Support
Staff member
Code:
[color=Blue]Symbol  [/color][color=Purple]press_Button [/color][color=DarkCyan]= [/color][color=Purple]PinC.4[/color]


[color=Black]Main:
      [/color][color=Blue]if [/color][color=Purple]press_Button[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]then [/color][color=Black]PlayTune          
      [/color][color=Blue]pause [/color][color=Navy]10
      [/color][color=Blue]goto [/color][color=Black]main                     [/color][color=Green]'loop back to main[/color]




[color=Black]PlayTune:
      [/color][color=Blue]pause [/color][color=Navy]10  [/color][color=Green]'debounce loop until pin is released
      [/color][color=Blue]if [/color][color=Purple]press_Button[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]then [/color][color=Black]PlayTune          


      [/color][color=Blue]setint [/color][color=Navy]%00010000[/color][color=Black],[/color][color=Navy]%00010000 [/color][color=Green]'interrupt on
      [/color][color=Blue]tune [/color][color=Navy]0[/color][color=Black], [/color][color=Navy]7[/color][color=Black], [/color][color=Blue]([/color][color=Navy]$40[/color][color=Black],[/color][color=Navy]$48[/color][color=Black],[/color][color=Navy]$43[/color][color=Black],[/color][color=Navy]$4A[/color][color=Black],[/color][color=Navy]$50[/color][color=Black],[/color][color=Navy]$58[/color][color=Black],[/color][color=Navy]$53[/color][color=Black],[/color][color=Navy]$5A[/color][color=Black],[/color][color=Navy]$50[/color][color=Blue])
      setint [/color][color=Navy]0[/color][color=Black],[/color][color=Navy]0 [/color][color=Green]'interrupt off
      [/color][color=Blue]goto [/color][color=Black]Main[/color]


[color=Blue]interrupt:
      pause [/color][color=Navy]10
      [/color][color=Blue]if [/color][color=Purple]press_Button[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]then [/color][color=Black]interrupt
      [/color][color=Green]'don't need to do anything apart from return
      [/color][color=Blue]return[/color]
 

1968neil

Senior Member
is there any way of returning to just before the tune is played on release of the input pin ?
so when the interrupt happens ie: the switch is pressed it interrupt the tune and then play the tune when it is released again ?

probably not but worth the ask :)
 

hippy

Technical Support
Staff member
The interrupt will always return to the command after the TUNE command, so you could wait for the button to be released after the TUNE command or even within the interrupt, then simply play the tune again.
 
Top