Monitoring how long an input is down

gtslabs

Member
I have some code to increase or decrease a 16 bit variable and display it on a LCD (using the terminal for now). IT is working fine but my code may be cumbersome.

But I need a way to increase my step size of my increment based on how long an input pin is depressed. So every 5 seconds increase the step size by a factor of 10 until it is released then set the step size back to 1.

I am not sure how to do this. Is there any feature for this?

Here is my code:

<code><pre><font size=2 face='Courier'>
'Frequency range is limited to 1 to 9999
'Display as frequency / 10,000 on the LCD

Symbol Frequency = W0
Symbol Stepsize = W1
Stepsize = 1
'Stepsize=10
'Stepsize=100
'Stepsize=1000
Main:

If pin2 = 1 then incfreq
if pin3 = 1 then decfreq
goto main

Incfreq:
pause 250
If Frequency&gt;9998 then limitMax:
Frequency = Frequency+Stepsize
Goto LCDOUT
Limitmax:
Frequency = 9999
Goto LCDOUT

Decfreq:
pause 250
If Frequency&lt;2 then limitMin:
Frequency = Frequency-Stepsize
Goto LCDOUT
Limitmin:
Frequency = 1
goto LCDOUT


LCDOUT:
If Frequency &lt;10 then display10
If Frequency &lt;100 then display100
If Frequency &lt;1000 then display1000
If Frequency &lt;10000 then display10000


Display10:
Sertxd(&quot;0.000&quot;,#Frequency,13,10)
goto main

Display100:
Sertxd(&quot;0.00&quot;,#Frequency,13,10)
goto main

Display1000:
Sertxd(&quot;0.0&quot;,#Frequency,13,10)
goto main

Display10000:
Sertxd(&quot;0.&quot;,#Frequency,13,10)
Goto Main
</font></pre></code>
 

MiB1986

Member
Hello,

can you not use pulsin, so it times the distance between the pressing and depressing.

like someone running from one post to another being timed, and then using that value for ur aplication?

I may be wrong but if im right it may help...

Kind Regards
 

MiB1986

Member
Hello,

here is a very crude quickly thrown together version of what i mean.

this is using an 08m,

but works fine for me...

__________________________code_____________________
begin:
if pin1 = 1 then counts
if pin1 = 0 then reset
goto begin

counts:
b0 = b0 + 1
goto begin

reset:
if b0 = 0 then begin
b1 = b0
b0 = 0
goto begin
__________________________code_____________________
 

boriz

Senior Member
This works. Could shorten your code a little:

<code><pre><font size=2 face='Courier'>
f=pin2*s-pin3*s+f
</font></pre></code>
 

boriz

Senior Member
<code><pre><font size=2 face='Courier'>
do
pause 100
inc t
f=pin2*s-pin3*s+f
if pin2+pin3=0 then
s=1
else
if t&gt;50 then
s=s*10
t=0
endif
endif
loop
</font></pre></code>

This just an idea for you to play with. Variable T is a timer that increments every 100ms so T=50 is 5 seconds. Note: Untested.
 
Top