Newbie-programming switch times

Racer_Rob

New Member
Just a simple question,
(i realise the answer is probably in a manual but I'm running a bit short of time)

I have a 7seg display and a picaxe-18 chip, the code below shows a section of what I have at the moment, label_3 displays number 3. Then if one switch is closed the number increases, the other switch decreases the number and the third switch resets to number 5.
The inc/dec switches are controlled by tilt switches but to stop an accidental knock causing the number to change how can i programme it so that the switch needs to be closed for, say, 0.5sec before the jumps to the next number?

Code:
label_3:	let pins=%01001111
		pause 500
label_3a:	if pin6=1 then label_2
label_3b:	if pin7=1 then label_4
label_3r:	if pin1=1 then label_5
		goto label_3a

label_4:	let pins=%01100110
		pause 500
label_4a:	if pin6=1 then label_3
label_4b:	if pin7=1 then label_5
label_4r:	if pin1=1 then label_5
		goto label_4a
Many thanks :)
 

boriz

Senior Member
You need to measure time. This will require some sort of loop and counter.

Code:
‘pseudocode
do
	inc time
until time>limit
But you are testing switches, so you need to put that in your loop:

Code:
‘pseudocode
do
	inc time
	test switch
loop until time>limit
You can manipulate the TIME variable or the LIMIT variable within the loop, based upon the switch condition.

You can test different switches for different intervals:

Code:
‘pseudocode
do
	inc time
	test switch1 : if on, inc variable1:if off, variable1=0
	test switch2 : if on, inc varibale2:if off, variable2=0 
	pause 10
loop until time>limit or varible1 > limit1 or variable2 > limit2
This pause is for 10 milliseconds. So a 0.5 second limit would be 50.

This is just one approach of many. Experiment!
 
Top