Shop OBEX P1 Docs P2 Docs Learn Events
MIN and MAX settings — Parallax Forums

MIN and MAX settings

eagletalontimeagletalontim Posts: 1,399
edited 2009-01-28 18:02 in General Discussion
I was wondering exactly how MIN and MAX works.

If I put :

temp1  VAR  Byte

temp1 MIN 0
temp1 MAX 255

temp1 = 250
temp1 = temp1 + 20




Would temp1 only go to 255 and not loop back to 0? Same goes if temp1 = 10 and I subtract 20. I know that if a variable exceeds its limit, it will loop back to the beginning. I don't want this to happen.

Comments

  • Mark HubersMark Hubers Posts: 19
    edited 2009-01-28 16:11
    The question I have for you is: What do you want to see happen? Add pass 255 or just max at 255?

    I
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-01-28 17:30
    luckily I found an old SX chip that I burnt a few pins on and I was able to test it. Sorry if my question sounded stupid, but the chip with the program on it was already soldered to the board and I could not debug from it. After testing it, I found that the min and max really did not work the way I thought it would. I tried temp1 = 10 - 30 and it looped back around to 236. Is there any command to really limit the MIN and MAX without it looping if it exceeds the limit? Even if I set the MIN to 1, it will still loop back around.

    Here is the code I am working with :

    values1(13) is 255
    values1(14) is 82

    ANALOGIN InPin, OutPin, temp1, 5
      temp1 = values1(13) - temp1
      temp2 = values1(13) - values1(14)
      tmpW1 = temp1 * 100
      tmpW1 = tmpW1 / temp2
      temp1 = tmpW1_LSB
      RETURN temp1
    



    It should return a value 0 to 100. If the ANALOGIN ever returns 81 or lower as the result, it will loop back around to 255. I do not want it to do that.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-01-28 18:02
    aaa. blonde moment. I figured it out. Simple IF statement made it all better [noparse]:)[/noparse]
Sign In or Register to comment.