Is there a command i can use to read a pin when its activated by a switch accurately.I've tried to use pulsin and i'm not getting an accurate readings.
erastusk: What's not intuitive is that you have to force an input pin high when you want it high and low when you want it low.· See the sketch attached, which will make your pin read low (if in4=0) when the switch is open as pictured, and the pin will read high (if in4=1) when the switch is closed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ·"If you build it, they will come."
Hi Erco and Dave,
I was using the if·then code you just posted and wasn't getting really reliable data.However, i was trying to mimick a switch with just a wire, so i think i might need to build an actual switching device to test it.
Thanks guys
A wire works as a switch, just be sure that you hold it tight (when debugging) so that you get less jitter in your output and you can see what happens when.
era: Something's wrong if you can't read a pin 100% reliably with this basic setup. Not sure what stamp and setup you have, but try this: connect pin 0 to ground (Vss)·through a 10K resistor, then use a wire to make & break a connection from pin0 to Vdd (NOT Vin) while running this code:
a[noparse]:D[/noparse]EBUG IN0
GOTO a
you'll get 1's when you make the connection and 0's when you break it. If not, all is lost, abandon ship!
One you verify that works, check your code for IF/THEN errors.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ·"If you build it, they will come."
I agree with Erco, but add a BIN1 to the program:
DO
DEBUG BIN1 IN0
LOOP
Eratusk, What do you mean by accurately in "read a pin when its activated by a switch accurately"? What do you want to happen when the switch is pressed and then released?
Hi Guys,
What i meant by accurately is when i ran the if IN4 loop, i would get 1s and 0s even when the wire was not connected or get the same thing when the wire was connected.
The problem was with the wire itself, it wasn't making contacted with the pin without moving.When i held it tightly it worked.Since I'm using a breadboard this shouldn't be a problem when i solder it.
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
I was using the if·then code you just posted and wasn't getting really reliable data.However, i was trying to mimick a switch with just a wire, so i think i might need to build an actual switching device to test it.
Thanks guys
a[noparse]:D[/noparse]EBUG IN0
GOTO a
you'll get 1's when you make the connection and 0's when you break it. If not, all is lost, abandon ship!
One you verify that works, check your code for IF/THEN errors.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
DO
DEBUG BIN1 IN0
LOOP
Eratusk, What do you mean by accurately in "read a pin when its activated by a switch accurately"? What do you want to happen when the switch is pressed and then released?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
What i meant by accurately is when i ran the if IN4 loop, i would get 1s and 0s even when the wire was not connected or get the same thing when the wire was connected.
The problem was with the wire itself, it wasn't making contacted with the pin without moving.When i held it tightly it worked.Since I'm using a breadboard this shouldn't be a problem when i solder it.
My Fault, thanks Guys