Command for getting input
slackjack
Posts: 25
Hey all,
Here is the situation. I have this circuit thats always high (+5V) by default (hooked up to a specific pin of the basic stamp). I wish to tally the number of times it changes from high to low and store it in a variable for future reference. Whats the best way to do this?
--thank you
Here is the situation. I have this circuit thats always high (+5V) by default (hooked up to a specific pin of the basic stamp). I wish to tally the number of times it changes from high to low and store it in a variable for future reference. Whats the best way to do this?
--thank you
Comments
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I expect the change from high to low to be under 1 second, but greater that 700 ms ( I cant, at the moment say for sure). For all purposes, the environment is assumed noise free.
OldState································· 'Last stored condition of input pin.
CurrentState··························· 'Current condition of input pin
IF OldState <> CurrentState THEN Counter = Counter + 1·· 'If they are different, increment your counter.
ButtonPressTotal = Counter / 2···· 'This adjusts for a press and release regardless of how long someone holds the button down.
OldState = NewState··················'This will update the OldState variable.
Something along these lines should work.
Tommy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
(Frequently heard from other's)
Tommy, I know it wasn't designed to·x, but can you make it·do x·anyway?
·
old_state should always be 0, as this is used to compare to the current_state. When the two dont match, the counter should increment. So say the user enters 5, this means that the loop souldnt exit until the counter is equal to what the use entered. This implies that the signal should be changed 5 times for the counter to increment 5 times. But here is where the problem happens, the signal isnt broken 5 times, instead it is broken once (and the value of counter is always equal whatever the user entered).
It seems that it is reading the state of the pin too quickly, hence the once only increment. How can I solve this?
Is it this code thats suppose to solve that problem: ButtonPressTotal = Counter / 2 How is this suppose to help?
--thanks again.
Although there is only a small part of your program offered, I'll take a shot at what the problem is. This is only based loosely on the text of your message.
I must presume you are using the BUTTON comand to field the "signal" of which you speak. I suspect you don't have your BUTTON command in a loop. When BUTTON is used it is expected that you will have it in a reasonably tight loop, so the command gets continually re-exectuted, until the target state condition occurs. Once that happens, then the BUTTON command will branch to the routine you have specified as the TargetState routine. I suspect you are escaping that (necessary) BUTTON loop prematurely, or there is no loop at all.
If you provide the entire program it will be a good deal easier to troubleshoot it.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
I am not using the COUNT command. I am strictly just monitor the pin for a change in state, then do the necessary requirements when the state is changed. I will provide my code. If there is a way to do this with the COUNT command, I will be glad to give it a test run.
If you need further clarification, just let me know.
Post Edited (slackjack) : 11/9/2006 1:20:47 AM GMT
If userIN = userIN then EXIT ? won't this ALWAYS happen?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
When the pin is high for approx. 1 sec, the do loop reads it in too quickly (and increments the counter multiple times within that 1 sec period). So if I wanted the pin to be high 5 times to exit the loop, it will be high only one time before the loop exits.