Programming Help BS2 For Next IN pin...
neoteric
Posts: 144
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.
I know this is probably obvious, but I have not been able to find an example for the last two hours.· Thanks for helping.
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.
Comments
For x = 0 to 11 step 2
FREQOUT x,1,37500 'transmit
x=x+1
irDetect = input x
Next
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
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.·
Make: INPUT Y
read: IN Y
Regards,
Bruce Bates
Bruce,
I think I am doing this as you suggested, but I am getting an error on IN y.
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