INPUT Command Help
ajs2001tx
Posts: 25
After reading the syntax guide I still have a question.·
I have a limit switch that am going to connect to ground and when the limit switch is toggled I want it to obviously pull·a pin low.· Because I don't want to pull two wires about 30 feet on a piece of equipment instead of just one.· So is that just done by:
LS PIN 1·····
INPUT LS···· 'Setting the LS pin as an input
????
I am being thrown a curve by the following wording from the PBASIC Help INPUT section.
[img]mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2\PBASIC.chm::/graphics/bs2all_inline.gif[/img]
Setup: INPUT 4Hold: IF (IN4 = 0) THEN Hold ' Stay here until P4 is 1
The code above will read the state of P4 as set by external circuitry. If nothing is connected to P4, it will alternate between states (1 or 0) apparently at random.
How fast is the alternation?·
And then if it as at a 1 then pulled to a 0 will it then "learn" and stay at a 1 waiting on the next 0?
I am just a farmer trying to automate piece of equipment so be patient with me on learning a new language like PBASIC.· ha ha.
Thanks for your help.
Andy
I have a limit switch that am going to connect to ground and when the limit switch is toggled I want it to obviously pull·a pin low.· Because I don't want to pull two wires about 30 feet on a piece of equipment instead of just one.· So is that just done by:
LS PIN 1·····
INPUT LS···· 'Setting the LS pin as an input
????
I am being thrown a curve by the following wording from the PBASIC Help INPUT section.
[img]mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2\PBASIC.chm::/graphics/bs2all_inline.gif[/img]
Setup: INPUT 4Hold: IF (IN4 = 0) THEN Hold ' Stay here until P4 is 1
The code above will read the state of P4 as set by external circuitry. If nothing is connected to P4, it will alternate between states (1 or 0) apparently at random.
How fast is the alternation?·
And then if it as at a 1 then pulled to a 0 will it then "learn" and stay at a 1 waiting on the next 0?
I am just a farmer trying to automate piece of equipment so be patient with me on learning a new language like PBASIC.· ha ha.
Thanks for your help.
Andy
Comments
·· Unconnected inputs are said to be "floating".· This means the line isn't being pulled HIGH or LOW.· Stray EMI can cause the line to do just about anything.· There is no pattern.· Sometimes it won't toggle at all, but it will usually.· For this reason a pull-up to the opposite of the active state is used.· If your input (Pushbutton) is active LOW, then you would use a 10K resistor to pull the line HIGH when the button isn't pressed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
···· Thanks for responding.· I understand now.· I have read about pullup and pull downs in Scott Edwards' book no less than 15 times but for some reason you just brought it home for me.· So I guess I would use the INPUT command in the code then?
··· As a discussion topic,·his book also says that it really doesn't matter what size resistor you use but keep it between 1k and 100k.· So in an effort to make things more difficult than they have to be, if you had to choose between only a 1k or 100k which would you choose?· And would the choice be the same for both pull up and pull down?
Thanks again,
Andy
Post Edited (ajs2001tx) : 10/1/2005 8:39:51 PM GMT
·· By default, on power-up the BASIC Stamp I/O pins are inputs.· Unless you make them outputs, or use a command which does so, such as HIGH, LOW, etc. they remain INPUTs.· So in your code you don't need to specify a pin as an input at the beginning.·
·· Another approach is to define the state of all the pins right at the beginning of your code with one line of code.· You can use DIRS = %1111000011110000 as an example to make P0 - P3 inputs (Remember, binary reads right to left), P4 - P7 outputs, P8 - P11 inputs and P12 - P15 outputs.· Until changed, either by the DITS register, or by a command, such as mentioned above, they will remain this way.· You can also define groups of pins, but that is covered in the manual and/or help files·as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com