Re Help me before i go mad please
Kurt Ingleson
Posts: 2
I am trying to get my bs2 with boe board to read the value of 4 pins at once , and depending on their state set another pin either high or low. however i cant get it to work, for example
if pin1 = 1 and pin2 = 0 and pin3 = 0 and pin4 = 0 then goto (etc etc) but then on another line
if pin1 = 0 and pin2 = 1 and pin3 = 0 and pin4 = 0 then goto ( another command)
and so on and so on, can this even be done and if so how can i get it to work, ie examples of code etc etc
thanxs for your help guys , i am new to the bs2 so please go easy on me hehe
·
if pin1 = 1 and pin2 = 0 and pin3 = 0 and pin4 = 0 then goto (etc etc) but then on another line
if pin1 = 0 and pin2 = 1 and pin3 = 0 and pin4 = 0 then goto ( another command)
and so on and so on, can this even be done and if so how can i get it to work, ie examples of code etc etc
thanxs for your help guys , i am new to the bs2 so please go easy on me hehe
·
Comments
That way you can branch if the nibble (INA for example representing pins 0,1,2 and 3) that make up a number from 0 to 15
branch if INA = 4 for example would mean pin 3 is high, If INA = 15 then all 4 pins are high.
That way you eliminate lots of code. Using lookup in combination with branching can also be done to reduce code size.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
my email is kurt.ingleson@virgin.net
or is there any existing i could modify on the net , thanxs for your help so far can you help a bit more
thanxs thanxs
You can't go through life using other peoples code, it will do you no good to plug in snippets of code without a full understanding of what it dose or how it works. Once you understand fully what a simple thing like this is, you will be off and running with all kinds of code.
Start with a main label and a goto main. In between make use of the debug command to see what is happening when the code is run using just one thing that does nothing but communicate back to you information that shows you what is happening.
The time you are taking to find other peoples code, you could have experimented and figured out how it works by now.
Just DO IT. Post the code you write if you have trouble with it and I am sure people here will point out mistakes. Mistakes are what burn in the learning.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
I am not trying to hijack this post
I want to understand how you do this
Think about using pins 0..3 and use the memory variables INS (see BASIC Stamp 2 Series RAM Organization in the basic stamp help Memory Organization and Variables)
That way you can branch if the nibble (INA for example representing pins 0,1,2 and 3) that make up a number from 0 to 15
branch if INA = 4 for example would mean pin 3 is high, If INA = 15 then all 4 pins are high.
That way you eliminate lots of code. Using lookup in combination with branching can also be done to reduce code size.
I know that if you want to see a pin state that you use this
INPUT 7······························ ' Make P7 an input
· DEBUG "State of P7: ",
······· BIN1 IN7, CR
Would I use this to·see the state of·Pins 0-3
State· VAR· INS····
· DEBUG "State of INA: ",
······· BIN1 INA, CR
If this is wrong then would you··
Please give me an example how you would see the state pins 0-3
I have no way of trying this now to see if this would work or not to night
with a Basic·Stamp
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/30/2009 3:49:38 AM GMT
Almost!!
BIN1 will only give you one digit.. use BIN4
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Smile ... It increases your face value!
The BRANCH command is what you want.
I put in a few other things but the point here is to copy the pin states to a variable and use that variable in your logic.
Remember a pin can change state within a command if you are operating on it's value.
There is no branch that will do a gosub so I put a return address under the branch statement so program flow can return to the statement after the branch statement. A psudo gosub command.
Hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
ON condition GOSUB routine
For example,
to cover all 16, and then return to the instruction after the ON .. GOSUB
Kurt might only need a lookup though, or a computation.
Set the state of pin p15 depending on the 16 possibilities for 4 buttons on inA, using lookup table. The same sort of logic can apply if there are multiple output pins associated with the 16 possible input states.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I remember now he old Qbasic on gosub, brings back old memories of the commodore64 as well.
One of the main points as you note above is realizing the number of possibilities or states and then designing the logic to handle all of them instead of just some of them.
Boolean logic using and, not or and xor are also possibilities to set up logic and branching for input on 4 pins.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Right you are about that! Rereading Kurt's original post, there are quite a few ways one could interpret what he is trying to accomplish. "Help me before I go mad" is often a question of "what do I really want to do, and why?"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thank you both for explaining·how to do this in·some much detail
IF MYFLAG=0 THEN
DEBUG "ALL OTHER COMBINATIONS "
GOSUB SHOWVAR
ENDIF
MYFLAG=0
ALLPINSZERO:
·DEBUG "ALL PINS ARE ZERO "
·GOSUB SHOWVAR
·
PINS012SET:
·DEBUG "PINS012SET "
·GOSUB SHOWVAR
DIR15=1··'·make·p15·an·output
LOOKUP·inA,·[noparse][[/noparse]1,0,1,1,0,0,1,1,1,1,0,0,1,0,1,1],·OUT15
Thank you for pointing this out to me
MrBi11
··DEBUG·"State·of·INA:·",
········BIN4·INA,·CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam