Out Put Going High after three Presses

Bozambo

Member
I would like to make one of the outputs of a picaxe turn on after three presses but the event must take place within a specified time say one or two mineutes after which it must reset, prepared to carry out the next cycle. Iwould like it to work as follows:press
Press
Press
Led On
wait 2 seconds
End Sequence and Resets waiting for the next cycle.
Lets say one or two presses are made inadvertently it should reset after the time lapse has taken place.
I have tried using both the count, procedures , and Interrupt comands but to no avail.
 

nick12ab

Senior Member
You don't need to use the count command or procedures - what you should use is the timer - this is supported by all M2, X1 and X2 parts.

This is example code for the M2 PICAXEs:
Code:
symbol timeout = 120			'Set timeout in seconds
symbol presscounter = b4		'Variable to hold number of button presses
symbol inputpin = pinC.1		'The pin the button is connected to
symbol outputpin = C.0			'The pin the LED is connected to (down to ground)	

	do
		if inputpin = 1 then	'Use 1 for a button connected to Vdd, use 0 for a button connected to Vss
			inc presscounter
			do : loop until inputpin = 0
			time = 0
			if presscounter = 3 then
				high outputpin
				pause 2000
				low outputpin
				presscounter = 0
			end if
		end if
		if time > timeout then
			presscounter = 0
		end if
	loop
This is an example for X1 and X2 PICAXEs:
Code:
symbol timeout = 120			'Set timeout in seconds
symbol presscounter = b4		'Variable to hold number of button presses
symbol inputpin = pinC.1		'The pin the button is connected to
symbol outputpin = C.0			'The pin the LED is connected to (down to ground)	

	settimer t1s_4
	do
		if inputpin = 1 then	'Use 1 for a button connected to Vdd, use 0 for a button connected to Vss
			inc presscounter
			do : loop until inputpin = 0
			timer = 0
			if presscounter = 3 then
				high outputpin
				pause 2000
				low outputpin
				presscounter = 0
			end if
		end if
		if timer > timeout then
			presscounter = 0
		end if
	loop
Both these pieces of code have been tested in the simulator and work.

If you must do this in Logicator, the conversion is pretty simple - the loop at the very end is simply a long line back to the start, an if command is the decision cell and the commands that make a variable equal something else (e.g. timer = 0) use the express cell.
 

Bozambo

Member
Hi Nick
Thanks for your responce to my inqiury. However the reason Iam using Logicator is because Iam not very conversant with basic coding.
What is a very simple matter for you is not entirely so for me. Trying to interpret the code is like trying to translate an indepth instruction in a language you have just started learning. So I hope Iwould not be asking too much. Could you give me it in a flowchart. That is what Ican understand. A rough freehand sketh would be good enough. It does not have to be elaborate Iwill understand it.

Thanks again
Bo
 

nick12ab

Senior Member
Hi Nick
Thanks for your responce to my inqiury. However the reason Iam using Logicator is because Iam not very conversant with basic coding.
What is a very simple matter for you is not entirely so for me. Trying to interpret the code is like trying to translate an indepth instruction in a language you have just started learning. So I hope Iwould not be asking too much. Could you give me it in a flowchart. That is what Ican understand. A rough freehand sketh would be good enough. It does not have to be elaborate Iwill understand it.
Ok I've attached the flowsheet for both M2 parts and X1/X2 parts as the only difference between the two is that for the X1/X2 parts the settimer command needs to be added at the start using a BASIC cell.
 

Attachments

Top