Shop OBEX P1 Docs P2 Docs Learn Events
BS2 If -Then Project — Parallax Forums

BS2 If -Then Project

ArchiverArchiver Posts: 46,084
edited 2002-12-29 13:47 in General Discussion
Hello

I am working through a project that uses the If-Then statement to
decide which routine to run. The If -then statement looks at which
pin input is high and which is low, and makes a decision as to which
routine to run. Once the routine has been completed, the program
then goes back to the If-then to see what to do next.
What I would like it to do is go through each routine once only.
That is, if the program sees the output from the If-Then statement
hasn't changed, the program loops the If-Then until it does see a
change.
At present it goes through the routine until the end of its task,
goes back to the If-Then seeing that it is still the same value and
runs the same routine again. (this could cause damage).
I have been looking through the BS2 commands and haven't come across
something that I recognise as helpful. To me, the idea would be to
record the If-Then result and when the program came back it could
compare the old result with the new result - if equal it would keep
looping - if different then it would move on. Of course after the
old result has been used, it is written over by the new result etc.

If someone could help with a hint it would be greatly appreciated.

Thanks Kim

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-12-29 13:47
    Kim-

    pin_state VAR WORD
    pin_mask CON %0011010111001010 'or whatever

    awaitChange:
    IF INS & pin_mask = pin_state THEN awaitChange
    pin_state = INS & pin_mask
    'followed by routine selection logic

    This checks for changes among all 16 I/O pins. If you have only a
    few pins to check, you could use a byte- or nib-wide version with
    INL/INH or INA/INB/INC/IND. The purpose of pin_mask is to limit
    which pins are considered for input changes within the selected I/O
    pin subset--may not be necessary depending on which pins count.

    Regards,

    Steve

    On 29 Dec 02 at 12:52, krcnz krcnz@y... wrote:

    > Hello
    >
    > I am working through a project that uses the If-Then statement to
    > decide which routine to run. The If -then statement looks at which
    > pin input is high and which is low, and makes a decision as to which
    > routine to run. Once the routine has been completed, the program
    > then goes back to the If-then to see what to do next. What I would
    > like it to do is go through each routine once only. That is, if the
    > program sees the output from the If-Then statement hasn't changed,
    > the program loops the If-Then until it does see a change...
Sign In or Register to comment.