Pin useage theory
AIman
Posts: 531
I am working on a new project that requires use of specific pins at specific times but it must relate to an incoming command to function. The programming isn't a concern right now so much as the theory, any input would be appreciated.
High level overview.
The BS2 is being used to control several different compents, two solenoids, one servo, 6 sonar and a lights and siren setup (I got bored with no sound).
So for Pins 1 and 2 they are directly relation to pin 3
When pin 1 is high pin 2 is low. When pin 2 is high pin 3 can be used but may not need to be. When pine 3 is used pin 1 must be low and pin 2 must be high.
First question -· Can a if statment say that if Pin 1 is low pin 2 is high and vise versa? I have not yet been able to figure that out from my materials and haven't been able to get that programming to work. I have this -
if pin 1 high then pin 2 low
If pin 2 high then pin 1 low
if pin 3 high then pin 2 high and pin one low
Is that about right?
Second question - Can I run a if statment to say that if pin 3 is needed pin 2 must be high? This relates to number one directly but am not sure if the theory on question one is correct
Third question - can an if statment be used so that if pin 3 is required it forces pin 2 high and pin 1 low? This also relates to question one and needs a·theory check.
Pin 4 runs the servo which can be used at any time and typically is used most of the time
if pin 4 high and pin 2 high or pin 1 high then
·· (insert code here)
end if
The rest of the pins run as follows.
Pin·5 through 11 run sonar and cycle through these non stop until the program is terminated. The data is always feed out of PIN 16.
Pin 12, 13 and 14 are for the lights and siren and pin 16 for host hook up
Pin 16 is the I/O for communicating with the host.
Question four - can I run all three items off one pin without having gaps in light and sound?· Right now I am keeping pin 12 high all the time by using
do while pin 16 <> stop··· ' Pin 16 I/O with Host
·· pin 12 high
loop
Given this work load would these things over load a BS2?
Would a BS2p be a better choice?
·
High level overview.
The BS2 is being used to control several different compents, two solenoids, one servo, 6 sonar and a lights and siren setup (I got bored with no sound).
So for Pins 1 and 2 they are directly relation to pin 3
When pin 1 is high pin 2 is low. When pin 2 is high pin 3 can be used but may not need to be. When pine 3 is used pin 1 must be low and pin 2 must be high.
First question -· Can a if statment say that if Pin 1 is low pin 2 is high and vise versa? I have not yet been able to figure that out from my materials and haven't been able to get that programming to work. I have this -
if pin 1 high then pin 2 low
If pin 2 high then pin 1 low
if pin 3 high then pin 2 high and pin one low
Is that about right?
Second question - Can I run a if statment to say that if pin 3 is needed pin 2 must be high? This relates to number one directly but am not sure if the theory on question one is correct
Third question - can an if statment be used so that if pin 3 is required it forces pin 2 high and pin 1 low? This also relates to question one and needs a·theory check.
Pin 4 runs the servo which can be used at any time and typically is used most of the time
if pin 4 high and pin 2 high or pin 1 high then
·· (insert code here)
end if
The rest of the pins run as follows.
Pin·5 through 11 run sonar and cycle through these non stop until the program is terminated. The data is always feed out of PIN 16.
Pin 12, 13 and 14 are for the lights and siren and pin 16 for host hook up
Pin 16 is the I/O for communicating with the host.
Question four - can I run all three items off one pin without having gaps in light and sound?· Right now I am keeping pin 12 high all the time by using
do while pin 16 <> stop··· ' Pin 16 I/O with Host
·· pin 12 high
loop
Given this work load would these things over load a BS2?
Would a BS2p be a better choice?
·
Comments
2. "Pin 16" is a pseudo-pin, which indicates to a SERIN or SEROUT statement to use the 'progamming port'. That's a very important use, but I don't think you can use it for INPUT or OUTPUT statements.
3. The BS2 is a single tasking chip. It CAN hold a signal HIGH or LOW while doing something else. It CAN'T do a SERIN on two pins at the same time.
4. The BS2 has no "is needed" concept. I don't know what you mean by "is needed", or "is required". The BS2 knows HIGH and LOW, 0 or 1. Only you can define the mapping between your "is needed" and "is pin3 = 1". It's not clear from your post what you intended.
5.· If "pin 4 runs the servo", then pin 4 is an output.· This means "IF Pin4 = 1" is a non-sensical statement, because it tries to use Pin4 as an input.
"So for Pins 1 and 2 they are directly relation to pin 3" is a very ambiguous statement, and poor grammar.
We want to help, really we do.
In otherwords I can't have two pins high? I can only go one at a time regardless of the code?
HIGH 1
HIGH 2
' this will make both pin 1 and 2 high at the same time.
·
·· Actually, that will make P1 HIGH and then P2 HIGH.· To make them both HIGH at the same time you could do something like:
Of course, the direction registers for these pins must be set to outputs first.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support