Shop OBEX P1 Docs P2 Docs Learn Events
please help with BS2p / BS2px pollin and pollrun — Parallax Forums

please help with BS2p / BS2px pollin and pollrun

chewyewwahchewyewwah Posts: 4
edited 2007-09-27 02:09 in BASIC Stamp
HELP!
can ANYONE show me how to use POLLIN to read a serveral I/O input, say 8 inputs and trigger a· different POLLRUNs to sunroutines.
ie: each POLLIN will trigger· POLLRUN its oun subroutine,
I am very new to BS2p polling command,
please show me a simple example
Many Thanks!
Chew

Comments

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-09-26 05:49
    There is no direct way to do that without program intervention. You can have several active POLLIN sources, but there can only be one POLLRUN action. If any of the POLLIN events occur, then that one POLLRUN action will follow. Once the new slot is running, you could check the status of the input pins and branch from there to different routines. Keep in mind that the POLLRUN action is not really a subroutine. There is no "return" instruction that will take the program back to where it left off.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • chewyewwahchewyewwah Posts: 4
    edited 2007-09-26 09:13
    Many thanks Tracy Allen for your respond. let me try to understand you. Even if I POLLIN serveral I/Os, I cannot brunch to a POLLRUN according to the I/O status because I am only allowed one POLLRUN. Right?
    Actually, I am building Micro Sumos which has 3 line sensors, 4 object sensors. I have been using If - Then statment. I would like to use POLLIN and POLLRUN to hopefully improve the respond. therefore I need each sensor to trigger a different action. Any idea???
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-09-26 16:27
    Is your program doing other things while it is waiting for the input events, or can it just nap until an input changes? That is the easiest situation. When the event happens, it checks which input caused it, and then branches to the appropriate subroutine or RUNs the appropriate slot. There are locations in scratchpad RAM that can latch events at the inputs.

    It is harder if the Stamp is has to be doing other things while waiting for the input events. Is it okay for it to leave at any point without bad consequences? Say, it is running a servo to move it to a certain position, and right in the middle of that an input event happens. Is it okay for it to jump out of that servo routine to handle the input event, maybe not knowing where it left the servo? You have to write code more carefully to handle those situations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • chewyewwahchewyewwah Posts: 4
    edited 2007-09-27 02:09
    Many Thanks. Need time to digest what you said.
Sign In or Register to comment.