PDA

View Full Version : Programming Help BS2 For Next IN pin...

neoteric
01-29-2006, 11:53 PM
I have a robot that has six ir pairs.· I am trying to figure out how to read pins in a loop.· pins 0,2,3,5,6 are transmitters.· Pins 1,3,5,7,9,11 are recievers.

For x = 0 to 11 step 2
FREQOUT x,1,37500 'transmit
irDetect = INX+1 '<----- WHAT SHOULD I DO HERE? All the examples use irdetect=in9 or whatever the in pin is
'do stuff
Next

I know this is probably obvious, but I have not been able to find an example for the last two hours.· Thanks for helping.

Steve Joblin
01-29-2006, 11:59 PM
Try this...

For x = 0 to 11 step 2
FREQOUT x,1,37500 'transmit
x=x+1
irDetect = input x
Next

Jon Williams
01-30-2006, 12:09 AM
Here's what I would suggest:

Emit····· DATA··· 0, 2, 3, 5, 6, 10
Detect··· DATA·· ·1, 3, 5, 7, 9, 11

Scan:
· FOR idx = 0 TO 5
··· READ Emit + idx, emitter
··· READ Detect + idx, detector
··· FREQOUT·emitter, 1, 37500
··· irDetect(idx) = INS.LOWBIT(detector)
· NEXT

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

neoteric
01-30-2006, 12:47 AM
thank you, I really appreciate the response

but this does not seem to work...·· This returns an "Expected a constant, variable, unary operator, or "("" error.· In the help file, it looks like input is used to set a pin as input, not to read it's input.·

DO
GOSUB drive
IF irdetect = 1 THEN
GOSUB Forward
ENDIF
IF irdetect = 0 THEN
GOSUB Park
ENDIF
LOOP

FOR x = 0 TO 11 STEP 2
FREQOUT 0,x,37500
y = x+1
irDetect = INPUT y
DEBUG HOME,"irDetect", DEC y, " = ",DEC irDetect,CR
NEXT
RETURN

Bruce Bates
01-30-2006, 01:13 AM
neoteric -

Make: INPUT Y

Regards,

Bruce Bates

neoteric
01-30-2006, 01:44 AM
Dan, Thanks· I have copied your code for later.· Since the rest of my code is not built on the array idea, I am going to try the other suggestions first.· Then I will try yours.· I would like to get this working before I takle arrays and data storage. (unless its the only way I can do it.)

Bruce,

' {\$STAMP BS2}
' {\$PBASIC 2.5}
' -----[ I/O Definitions ]-------------------------------------------------
x VAR Word 'just a temp variable
y VAR Word
irDetect VAR Word
'END 'save on batterys uncomment to stop stamp temporarily
'-----[Main Program]-------------------------------------------
DO
LOOP
FOR x = 0 TO 11 STEP 2
FREQOUT 0,x,37500
y = x+1
INPUT y
irDetect = IN y '<--- says IN is an undefined symbol.
DEBUG HOME,"irDetect", DEC y, " = ",DEC irDetect,CR
NEXT
RETURN

I think I am doing this as you suggested, but I am getting an error on IN y.

Jon Williams
01-30-2006, 02:04 AM
IN is not a PBASIC keyword.·· In the version above I had assumed irDetect would be an array of bits -- here's how to update that code so that irDetect is a Byte.

idx······ · VAR·· Nib
emitter··· ·VAR·· Nib
detector··· VAR·· Nib
irDectect·· VAR·· Byte

Emit····· · DATA··· 0, 2, 3, 5, 6, 10
Detect···· ·DATA·· ·1, 3, 5, 7, 9, 11

Scan:
· FOR idx = 0 TO 5
··· READ (Emit + idx), emitter
··· READ (Detect + idx), detector
··· FREQOUT·emitter, 1, 37500
··· irDetect.LOWBIT(idx) = INS.LOWBIT(detector)
· NEXT

You input pins should never be made outputs so you don't need to complicate things by using the INPUT function.· This routine gives you the most flexibility to assign your emitter/detector pin pairs (in the DATA tables)·without resorting to monkey-motion with your for next loop -- monkey-motion that, if it goes wrong, could be driving outputs into each other and creating a conflict.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax