Touch sensor interrupts when pressed for 2 seconds

nanogear

Member
Hello,

I have this code:

Code:
#PICAXE 08M2
symbol TOUCHCONFIG = %00001001
;time = 0
main:	
      ;pause 100
      touch16 [TOUCHCONFIG], C.4,w0	
	if w0 > 3600 and time = 2 then 
	   goto subrutine		                  
	   else 
	   goto main 
	endif
	return
	
subrutine: 
           low B.2
           pause 2000
           high B.2 , B.0
           time = 0
           do
               touch16 [TOUCHCONFIG], C.4,w0	
	         if w0 > 3600 then 
           loop
           end if
           goto main
Is just a process that when a touch sensor is pressed for two seconds then execute a subrutine.

But I have a problem. The code jump to subrutine after 2 seconds only if I initialize the picaxe with the touch sensor pressed. In other words, when w0 > 3600 from the beginning. And if I initialize the picaxe and then touch the sensor, the code doesn't jump to subrutine as wished. I know is a code issue... please someone can tell me what is wrong with my code or what is mssing???


thank you so much!
 

hippy

Ex-Staff (retired)
If the program is started, you leave it ten seconds, then press and hold the touch sensor, the 'time' variable will hold a value 10 or more. The test ...

if w0 > 3600 and time = 2 then

Will never be true; time will not be 2.

The 'time' variable is measuring elapsed program time, not the time the touch sensor is held for. You need something like ...

Code:
Touch ...
If w0 > 3600 Then
  If time >= 2 Then
    Goto Pressed
  End If
Else
  time = 0
End If
 

nanogear

Member
The 'time' variable is measuring elapsed program time, not the time the touch sensor is held for. You need something like ...

Code:
Touch ...
If w0 > 3600 Then
  If time >= 2 Then
    Goto Pressed
  End If
Else
  time = 0
End If
Hippy, you always helping me. Thank you!!! Didn't noticed the issue about the time variable.
 
Top