Exit from Button

I am using the Button command on a 14M2, (pin c.3) inside an independent task.

The effect being sought is to wait until a switch has been pressed for a few seconds and thereafter increment a delay value for each couple of seconds it remains depressed. This can be done using the Delay and Rate options in the Button command.

What I cannot get my head around is how to detect when the switch has been released. Some guidance would be helpful because the answer is probably in the functional description but passing me by.

Putting a conditional test inside the action address code doesn't work because the program only ever gets to that point when the switch is depressed.

I have searched the forum for previous comment because I believe there was once a long thread on the Button topic though I have not yet found it. Most comments advise using an interrupt instead, but I don't think I can do this on pinc.3 of a 14M2 because the SETINT guide says "14M/14M2 only inputs 0,1,2 may be used" and I have no other spare pins.

My test code is:

Code:
Start3: ;read button 
b6=0
b4=0
buttonwait:
	button c.3,1,5,2,b6,1,pushed
	pause 1000
	goto buttonwait
	
pushed: 

	if hoursdelay < 9 then
	inc hoursdelay
	else
		hoursdelay=0
	endif
if pinC.3 = 0 then
	goto Start3 ; this never happens!
	else
		goto buttonwait 
	endif
	
end
 

hippy

Ex-Staff (retired)
I think the problem is that the "Pushed" code will only be called when the button has been pushed so it will never be seen as other than pushed in that routine.

You probably need a multi loop program. The first using BUTTON to determine when a first push occurs, a second loop using BUTTON to detect subsequent held repeats, and to abort when the button is released. Something like ...

Code:
Main: 
  Do
    Button C.3 , ... , Pushed
  Loop

Pushed:
  hoursdelay = hoursdelay + 1 // 10
  Do While pinC.3 <> 0
    Button C.3 , ... , Pushed
  Loop
  Goto Main
 
Hippy: Thanks, I had more or less got to a similar conclusion and will give it a try. Hopefully Button does not look for a state change to get started.

Oh, and thanks for the pointer to the mod/remainder function. I thought I had seen it somewhere.
 
This seems to work and do the job with only one Button statement. Messy structure though:

Start3: ;read button
b6=0
hoursdelay=0

buttonwait:
do while pinC.3 <> 0
button c.3,1,5,2,b6,1,pushed
pause 1000
loop
goto Start3

pushed:
hoursdelay = hoursdelay + 1 // 10
goto buttonwait

end
 
Top