PDA

View Full Version : Storing PIN into variable?



mgrey
08-19-2008, 09:44 PM
I have BS2e connected to several sensors of the same kind.
So, I want to use subroutines and select sensor before calling.
Something like this:

sensor1ĚCON 0
sensor2 CON 1

selectedsensor VAR Nib

selectedsensor = sensor1
getData
:
:
selectedsensor = sensor2
getData
:
:

getData:
PULSIN selectedsensor,0,Var
RETURN

According to documentation all commands taking 'Pin' can use variable as input, but the above does not work
I've tried to use PIN also, but no change!

What is the best way to solve this problem?

Mike Green
08-19-2008, 09:50 PM
What do you mean by "does not work"? Your idea is sound. I don't know if your "code" was intended to illustrate or be taken literally, but the "getData" should be "GOSUB getData".

mgrey
08-19-2008, 11:40 PM
Sorry, it was just an example, I missed the GOSUB of course.

I can not get it to work!

I will do some more debugging!




Post Edited (mgrey) : 8/19/2008 6:04:54 PM GMT

mgrey
08-21-2008, 02:20 AM
Sorry, I found it, defining pins as constants works.

The problem was that at one part of the code there was a check if a pin went low like:

DO:
:
:
LOOP WHILE sensor

this worked when sensor was defined as PIN, but of course not as CON

I solved it by:

DO

IF sensor = 0 THEN
sensorin = IN0
ENDIF

IF sensor = 2 THEN
sensorin = IN2
ENDIF

:
:

LOOP WHILE sensorin

It works but it is not so nice code!