Program with the Basic Stamp.
cedtinsi
Posts: 45
Welcome and Thank you for having any kind of interest in my title: Program with the Basic Stamp.
I actually have a question, and I would be pleased to have it answered.
The question is about writing codes executable by the Basic Stamp.
Here is the question: Can I force a IF... ELSE statement into another IF... ELSE statement ( I hope you understand what I am trying to insinuate)?
In a programing language such as the C language, I can do it.
I do not know how to do it with the PBASIC language.
Please you are welcome to give me some directions.
thank you.
I actually have a question, and I would be pleased to have it answered.
The question is about writing codes executable by the Basic Stamp.
Here is the question: Can I force a IF... ELSE statement into another IF... ELSE statement ( I hope you understand what I am trying to insinuate)?
In a programing language such as the C language, I can do it.
I do not know how to do it with the PBASIC language.
Please you are welcome to give me some directions.
thank you.
Comments
There is also a CASE statement which functions like multiple IF....THEN statements, but allows cleaner looking code.
Cheers,
The answer you provided me with was exactly what I needed; now, I am tempted to ask another question.
It concerns the decision time of the Basic Stamp when it tries to execute the commands of a program.
Specially, for the specific purpose of my question, I am interested in knowing the decision time associated to a AND linking.
For example (taken from page 78 of "What is a Microcontroller?" manual) consider the statement: IF (IN3=1) AND (IN4=1) THEN ................ELSEIF (IN4=1) THEN.....
In the statement above, what is the maximum time that the Basic Stamp allows to pass before it makes the decision on whether _both pin3 and pin4 are high_ or _only pin4 is high ?
The reason why I ask this question is because: It is practically impossible to know for sure that two different pins have been pressed at an exact same time; often time the pins are not pressed at an exact same time, and this to me can make a huge difference.
Again, your expertise will be greatly appreciated.
thank you.
It is practically impossible to know for sure that two different pins have been pressed at an exact same time; often time the pins are not pressed at an exact same time, and this to me can make a huge difference.
Here is the question: Can I force a IF... ELSE statement into another IF... ELSE statement
I would like to know the maximum amount of time difference between ( say, the moment pin3 is high and the moment pin4 is high) That will still cause the Basic Stamp to report or sense that both pins are high.
Thank you in advance.
http://www.emesystems.com/BS2speed.htm
If this is an operator pressed pushbutton, I think you are underestimating the speed of the micro. The BS is so fast it will be nearly impossible to push the buttons at the same time.... far as the BS is concerned BUT!! you would write your code in such a way that you "Capture" the event. For example
main:
IF IN1 AND IN2 THEN GOSUB simult
GOTO main
simult:
DEBUG "Both buttons pressed!"
RETURN
This little routine can be this simple or written as complicated as you need it to be.
If you press both buttons seemingly at the same time, but to the Stamp it sees a 20us difference between the two.... no matter. When the first button is pressed, the BS sees it, but it runs the check again because they're not both pressed and keeps checking until they are..... 20microseconds later the BS is still checking for button presses and sees both are made which fulfills all conditions. THEN prints "Both buttons pressed!" on your screen.
My guess would be 475 + 143 + 475 + 143 microseconds or 1.2ms for the BS2, but that's a guess.
Edit: Actually I bet it'll be just 475 + 143 microseconds (time for the first IF) but that's still a guess.
The only thing that you can do is this IF IN0 AND IN1 THEN " Your code
If you press both buttons seemingly at the same time, but to the Stamp it sees a 20us difference between the two.... no matter. When the first button is pressed, the BS sees it, but it runs the check again because they're not both pressed and keeps checking until they are..... 20microseconds later the BS is still checking for button presses and sees both are made which fulfills all conditions. THEN prints "Both buttons pressed!" on your screen. <...This the way this works
Now if you are asking is there a way to see if an input is HIGH for some amount of time and if goes LOW before that amount of time has past then you could use this
Now if you ask me if you use two Input ( the code routine above ) in a IF THEN I do not know that this will work for sure I have not try this
First and foremost, Thank you for your continuous help.
Yet I am still concerned.
Let's say that I have the following code lines in my program.
HIGH 14
HIGH 15
PAUSE 50
ELSEIF (IN3 = 1) THEN
HIGH 14
PAUSE 50
.
.
.
.
This is no invention of mine; in fact it can be found at page 78 of the "What is a Microcontroller ?" manual from Parallax.
My concern is:
The most chances being that pin3 and pin4 are never high at the same exact time, and assuming that pin3 is the first to be high, and pin4 follows with a delay of, say, 20us; based on the code lines above, can you please tell me what is going to happen?
Thank you.
Now if the Basic Stamps see input 4 first it would loop agian
This why I had this above what would happen is that if you have both button pushed basicly at the same time the top routine would run and if it only see input 3 was high only the it would run the bottom routine
If you put this in a DO LOOP It may not see that both button are pushed
I believe the question is, if you where to invoke the "IF (IN3 = 1) AND [(IN4 = 1) THEN" statement, what would happen if IN3 equals 1 at the beginning of the statement and IN4 went HIGH 20us after the IF command started processing, would it catch the IN4?
According to Dr. Tracy, the IF (Branching) command take about 340-450us to complete, if I'm reading them correctly:
http://www.emesystems.com/BS2speed.htm
I would think that after the command started processing, the inputs would already been read, so any change during the ~400us would not matter.
Again, not an answer, but a calculated guess based on information I have looked at..
I do appreciate your outstanding help.
Mr. Sam_Sam_Sam, I am impressed by the way you find solutions to problems, that is inspiring.
The code you wrote makes perfect sense to me.
I am still curious as to know the maximum amount of time delay that can be allowed, between the HIGH of one pin and the HIGH of another pin, such that the Basic Stamp will assume the pins to have been set at HIGH at the same time.
My curiosity is founded.
The foundation is that, I read the "What is a Microcontroller?" manual from parallax, and through the activity from page 77-78 , It clearly springs out that there is indeed the existence of such a 'maximum time delay'.
Having a precise idea of the range of that time delay is my inquiry.
I rest assure knowing that a help will come soon.
Thank you.
IF (IN3=1) AND (IN4=1) THEN
____
____
Could it be assumed, from the above example, that IN3 and IN4 are both tested for, and latched, before the IF is invoked?
It is a pleasure to know that you are around the corner to share your precious knowledge.
Sometimes an answer may just be empty; but still I appreciate the awesome job of yours, a valuable part in making this forum what it is.
Thanks.