holding a button over a time period

lake

New Member
hi i have four button that can be pressed ive put my picaxe 40x1 onto the bread board and the button that i need to press are really sensitive so to solve this i thought i could solve this by making the time period that the button is held but i need some help on doing this and if i put a wire into the input pin is thinks it a 1 so +v but its only a wire ive tried to put a resistor in but it just kept thinking it was +v but it wasnt any ideas will be great thanks alot
 

Tom2000

Senior Member
Lakey,

You can either connect your button to ground with a pullup resistor to +v connected to to the input pin, or connect your button to +v, using a pulldown resistor between the input pin and ground. Let's assume that you've connected a pushbutton on, say, the pin1 input, and a pullup resistor between pin1 and +v.

When the button is open, the pin will read high. When you push the button, the pin will read low.

Enter some debounce code like this:




<code><pre><font size=2 face='Courier'>



symbol Button = pin1



Main:

if Button = 0 then
do
pause 5
loop until Button = 1
pause 5
endif

.

.

.

end


</font></pre></code>


The 'if' statement will test your button. Normally, you'd put this in your program's main loop.

If it sees the button down, it will wait, testing the button ever 5 milliseconds, until the button is up.

It will then wait an additional 5 milliseconds to debounce the button-up transition.

HTH,

Tom







Edited by - Tom2000 on 13/07/2007 19:46:59
 

hippy

Technical Support
Staff member
There's also the BUTTON command. Never used it so cannot say how well it would work for a particular case.

The main thing is as Tom suggests, pull-up or pull-down resistors. Without those the button input picks up signals like an aerial and you get all sorts of annoying and odd behaviour.
 

Tom2000

Senior Member
I drove myself nuts trying to figure out how the button command works, then came to the conclusion that it doesn't. :)

Tom
 

lake

New Member
yh ill just have to get some pull up resistors anyone know any good places where to buy them with really fast postage :)


hmm if i put a pause in the code since im using a dotmatrix it will flicker so will another picaxe work using the something like

main:
if pin0=1 then gosub input1out
goto main

input1out:
high 1
pause 5
return
because ive got two picaxe 18 somewhere one should do as i only need 4 inputs and four outputs

Edited by - lakey009 on 13/07/2007 20:16:00
 

hippy

Technical Support
Staff member
The reason for adding a delay to debounce a button is so you don't come back and read it pushed or not while it's in an indeterminate state, &quot;bouncing&quot; against its mating surface. As long as you have enough of a delay between reads through the execution of your other code you may not need debouncing. Add the resistors first then see how it goes - Note only pull-up or pull-down, not both.

Fast sources for resistors - Any old PCB's you can cannibalise ?

If you are getting into electronics, a bag of E3, E6 or E12 helps, even a big handful of each of the common R's used in many PICAXE circuits; 22K, 10K, 4K7 and 1K.
 

sedeap

Senior Member
:::::::::::::::::.
Hippy the Hannibal Cannibal... HE HE HE
Really good are the old PC Mainboards to do this, or any other broken device.
Last month I found one glass-tube broken TV in my neighbour trash can, and recover from it Several dozens of components, and the remote control as well (with one pair of good AA NiMh in it)

:eek:)
 

Tom2000

Senior Member
ROTFL!!!

sedeap, your story takes me waaaaayyyy back!

When I was a young kid (in the era of tube TV sets), just learning how to experiment with electronics, I'd scour my neighborhood on trash day, pulling my little red wagon behind me, looking for discarded TV sets.

If I found one, I'd load it on my wagon, take it home, then strip the chassis for any possible useful components. I'd lovingly file every part in my collection of coffee cans, cardboard boxes, baby food jars, and just about any other scrounged container that looked useful.

After stripping a few discarded TV sets, I felt that I was rich beyond my wildest expectations! :)

Once, I actually managed to fix one of those discarded sets. An older round CRT machine. I set it, minus its cabinet, on a small table at the foot of my bed. I was the only kid in my neighborhood that had his very own bedroom TV! (I kept that uncased fire hazard in my bedroom all the way through high school.)

You've brought back some very pleasant memories.

Tom

PS - Lakey, the value of pullup and pulldown resistors isn't critical. Anything between about 2.7k and 47k should be suitable. Whatever you can scrounge should work.




Edited by - Tom2000 on 14/07/2007 11:45:36
 

lake

New Member
yh ive just got a playstation controller and ive ripped it to pieces lol found lots and im also using the little sticks that you move for the left and right buttons that i need thought it would be cool to play with thanks for your help
 

Tom2000

Senior Member
<i>yh ive just got a playstation controller and ive ripped it to pieces lol found lots and im also using the little sticks that you move for the left and right buttons that i need thought it would be cool to play with thanks for your help </i>
Way to go!

Good luck, and keep on tinkering!

Tom
 

hippy

Technical Support
Staff member
On recycling old PCB's, the best I've found are old VCR's, car radios, amplifiers, PSU's and stuff which is a decade old. I've found modern and multi-layer boards, motherboards and ISA/PCI cards to be hard to unsolder and not a lot on them anyway which is re-usable.

Electrolytic caps apparently deteriorate over time but I've noticed no problems, especially balanced against the cost of new ones.
 

lake

New Member
yh im just looking at some old motherboards that i have from computer that i never got around to finsh building them seen laods of stuff to steel off them lol thanks alot for all you help
 

premelec

Senior Member
I just scrounged some HV MOSFETs from compact florescent light ballasts - Older
cell phones have an array of MLC capacitors and the like...

Tom - you didn't mention holding the CRT plug end under water whilst breaking the the seal off and watching the CRT suck full of water :) Wear your safety glasses....
 
Top