Shop OBEX P1 Docs P2 Docs Learn Events
Storing PIN into variable? — Parallax Forums

Storing PIN into variable?

mgreymgrey Posts: 3
edited 2008-08-20 18:20 in BASIC Stamp
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?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-19 13:50
    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".
  • mgreymgrey Posts: 3
    edited 2008-08-19 15:40
    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
  • mgreymgrey Posts: 3
    edited 2008-08-20 18:20
    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!
Sign In or Register to comment.