Shop OBEX P1 Docs P2 Docs Learn Events
How do you write an if statement for # range going up verse going down — Parallax Forums

How do you write an if statement for # range going up verse going down

sam_sam_samsam_sam_sam Posts: 2,286
edited 2010-09-28 22:45 in General Discussion
I know to write an IF statement for range of #
Like

IF range >150 TO range < 300 THEN do something


_____________________________________________________________

Example 150 to 300 I only want the IF to be TRUE if value is going UP

how do write an IF statement one if you want it do something when the value is going up but not down

_______________________________________________________________

Example 300 to 150 I only want the IF to be TRUE if value is going DOWN

Then write an IF statement one if you want it do something when the value is going down but not going up


Would something like this work

IF Present_Reading > last_Reading + 1 THEN do something ' " value going UP "
IF Present_Reading < last Reading - 1 THEN do something ' " value going down "

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-09-28 12:32
    The simplest way that I can think of is to store a copy of your value and compare against it.

    Rich H
  • ercoerco Posts: 20,260
    edited 2010-09-28 14:59
    If newvalue>oldvalue AND newvalue>150 AND newvalue<300 then...
    ...
    ...
    ...
    oldvalue=newvalue
    return
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-09-28 22:45
    I have it working but this was a pain in the neck to write and get it to work right

    THANKS to erco and W9GFO for your :idea:

    checking:
    DO

    IF result0 = 0 OR result0 > 2070 THEN EXIT
    IF result0 < 890 OR result0 > 2070 THEN EXIT

    >>
    >> Code in side
    >>

    IF result0 < 890 OR result0 > 2070 THEN GOTO checking
    IF result1 <> Last_result0 THEN GOSUB OldReading ' This line reset Reading in RAM on power up

    IF result0 > result1 + 2 THEN 'Stamp Value Going UP
    GOSUB OldReading

    ' IF result0 < result1 - 2 THEN ' Stamp Value Going DOWN
    ' GOSUB OldReading

    ' ENDIF
    ENDIF
    PAUSE 100
    LOOP
    RETURN
Sign In or Register to comment.