I don't think it can be used to perform a different action based on how long the button is held for.This gives action like a computer keyboard key press - send one press, wait for 'delay' number of loops, then send multiple presses at time interval 'rate'. Note that button should be used within a loop. It does not pause program flow and so only checks the input switch condition as program flow passes through the command.
main:
time = 0
if pinC.1 = 1 then
do while pinC.1 = 1 : loop
if time > 3 then
goto thing1
else
goto thing2
end if
end if
goto main
thing1:
goto main
thing2:
goto main
#picaxe 14M2
setint %00000010,%00000010 [COLOR="#008000"] 'interrupt on pinc.1 high[/COLOR]
main:
do
[COLOR="#008000"] ' MAIN PROGRAM LOOP [/COLOR]
loop
interrupt:
pause 40 [COLOR="#008000"] 'Debounce switch [/COLOR]
if pinC.1 = 1 then [COLOR="#008000"]'Switch is still pressed[/COLOR]
time = 0 [COLOR="#008000"] 'Start timer[/COLOR]
do while pinC.1 = 1 [COLOR="#008000"] 'now switch has been pressed for about 20ms [/COLOR]
if time > 2 then goto long [COLOR="#008000"] 'switch held down for 3 sec & does not need to be released .[/COLOR]
loop [COLOR="#008000"] 'to jump to "long"[/COLOR]
goto Momentary[COLOR="#008000"] 'momentary press & release [/COLOR]
else [COLOR="#008000"] 'switch not held for at least ~40ms[/COLOR]
setint %00000010,%00000010
return
endif
Momentary: [COLOR="#008000"] 'Switch was pressed momentarily[/COLOR]
setint %00000010,%00000010
return
Long:[COLOR="#008000"] 'Switch held down for ~3 seconds[/COLOR]
setint %00000010,%00000010
return
interrupt:
setint %00000010,%00000000 'interrupt on pinc.1 low
<... rest of programme>
No it isn't. The interrupt is executed as a gosub and not a goto.also I must warn on using returns in interrupt routines. It is easy to get in the situation of nested loops or empty return stacks. Better use 'goto main' or whatever label tou wat to go to.