Shop OBEX P1 Docs P2 Docs Learn Events
Software Multiplexing??? — Parallax Forums

Software Multiplexing???

tommyctommyc Posts: 7
edited 2006-01-20 17:38 in BASIC Stamp
I am reading serial data into a BS2 from two sensors, and would like to reduce the program space required to process the input data (which is handled identically).·

Is there a way to use the same subroutine for two sets of I/O pins and variables?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-01-20 17:30
    Tommy -

    Sure, make the pin port number a variable name, and set it as you see fit.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-20 17:38
    Here's one way to implement Bruce's suggestion:

    SensorPin··· DATA··· 12, 15

    sensorDat··· VAR··· ·Byte(2)
    idx··········VAR···· Nib

    Get_Sensors:
    · FOR idx = 0 TO 1
    ··· READ SensorPin + idx,·sio
    ··· SERIN sio, Baud, [noparse][[/noparse]sensorDat(idx)]
    · NEXT
    · RETURN

    If your serial pins are contiguous (grouped together), you can set the value of sio with math instead of reading the pin numbers from a table.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.