button that has push on/off
stilgar
Posts: 47
I have searched, even looked at the obex. If I missed it, please point me to it.
But not found code to make a toggle method that 1 button is used to toggle a output.
Example, push it ounce and it turns on a led, push it again and it turns off the led.
thanks,
stilgar
But not found code to make a toggle method that 1 button is used to toggle a output.
Example, push it ounce and it turns on a led, push it again and it turns off the led.
thanks,
stilgar
Comments
Each time the button is pressed you execute the line below.
If the pin is high it will go low, if low it will go high
I have a question for you (again). We discussed this earlier but I need more assurance.
Does a switch not make multiple connections on both the make and break condition.
If this is the case don't we need two delays as follows:
detect make
wait
detect break
wait
to get it right
I am about done with the PASM book and would like to really clarify this, for the beginners, in the book.
Thanks
H
H
In both Spin and PASM I use a loop that reads the state of the switch and returns the state after it has remained the same x number of times through the loop.
I think this needs 4 total delays for one complete cycle
Am I right?
H
Based on your first post and this question I am assuming you have:
- A push button on a prop pin that closes a contact when it is pressed and opens the contact when released.
- A led on another prop pin that each time the button is pressed you turn on if it was off, or off if it was on.
You only need to:
detect make
wait
detect break
wait
if led is on turn it off
else turn led on
Thanks
H
I agree, not usually good to halt the loop. I did not want to make the answer any more complicated than necessary.
I have a small routine that reads in all the switches once each time through the loop, debounces them, and sets the switch variable to the proper state once they are debounced. Any routine that needs to check the switch status reads the appropriate bit of the variable for the state of that switch.
Unfortunately, this doesn't accomplish what the OP wants. The LED won't latch in this case. All it does is have the output equal the state of the input.
Mickster
This code has the debounce period at the end of the routine. Most programmers place the debounce period at the beginning of the routine. Normally open switches don't randomly push themselves down so if the button is sensed down it's because it was pressed down by the operator. The delay of 1/16 second will work for most switches and can be shortened or lengthened to suit to type of switch and your needs. Military specification switches are very reliable but they can bounce around for what seems like ages before finally settling down.
The problem is that it can repeat too quickly and look like it's not latching...
It's not really a debounce. Touchpads don't "bounce" inthe traditional sense.
A quarter second delay at the top of the loop helped settle it down.
That could be other code, of course, but for a demo (shrug)...
TOTO.SPIN
Touchpad driver: