PDA

View Full Version : Assigning multiple pin reading to a variable

silverback
02-15-2010, 06:58 AM
I know what I want to accomplish, but don't know where to start looking.

I am going to use a three button·station to control a boe-bot (via tether).
I have checked out the unit to make sure that (connect to p15) will read the pin state in real-time.
what I need to do is assign all three pin readings into a single· variable (for simplicity sake).
With this variable, the program will inform the bot which direction to go.
assuming the pins are 15 14 13
I need to have a variable that reads all three pin states to direct the bot.
each button will connect to a pin and control logic is as follows:

3ControlStation var byte
(needs to gather the following data)

in15 in14 in 13
·0···· 0····· 0 = forward
·0···· 1······0 = turn right
·1···· 0····· 0 = turn left
·0···· 0····· 1 = stop (unit has a normally closed button)
·1···· 1····· 1 = reverse

·What command would allow me to assign three pins to a variable?

Using BS2 and BOE Rev C.

Thanks for the help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you convince yourself that something is impossible before you even try; you are sure to prove yourself right.

Post Edited (silverback) : 2/15/2010 12:03:19 AM GMT

Mike Green
02-15-2010, 07:07 AM
All input pins are available in the input register INS. In addition, you can refer to each byte of INS as INL and INH. You can refer to each (4-bit) nibble of INS as INA, INB, INC, and IND. In your case, the three bits of interest are in an "inconvenient" position that's easily made convenient. If you use "IND >> 1", that will get you the 3 bits (IN15,IN14,IN13) as a single number from 0 to 7 (forward,stop,right,...,left,...,...,reverse).

silverback
02-15-2010, 06:51 PM
That did the trick and I think I understand the memory structure a little better now; thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you convince yourself that something is impossible before you even try; you are sure to prove yourself right.

silverback
02-17-2010, 08:59 AM
Mike Green said...
In your case, the three bits of interest are in an "inconvenient" position that's easily made convenient.
Mike, when you said that the bits are in an "Inconvenient" position, were you referring to fact that the servo· pulsouts are on 12 and 13 or that I would need to use the IND >> 1 command to get the NIB.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you convince yourself that something is impossible before you even try; you are sure to prove yourself right.

Mike Green
02-17-2010, 09:31 AM
"Inconvenient" just meant that the bits were not in the position needed and they needed to be moved into a more useful position with "IND >> 1".
·