Shop OBEX P1 Docs P2 Docs Learn Events
Min Max limit code help reqd — Parallax Forums

Min Max limit code help reqd

VeitchVeitch Posts: 2
edited 2011-07-11 10:30 in General Discussion
Hi,
I would like BS2 code to ignore any values say between values -10 to +10
I have posted my code which appears to work below, but is this the correct way to go about this?
Thanks

' {$STAMP BS2}
' {$PBASIC 2.5}
' This code ignores any values between limits -10 to +10
x VAR Word
x = -9 'Change these test values
Main:
IF (x > -10) XOR (x < 10) THEN x = 0
DEBUG SDEC x,CR
GOTO Main

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-10 15:48
    Veitch,

    Welcome to the forum!

    Your code will set x to zero if it's inside the interval (-10 .. 10), excluding -10 and 10. Is that what you want? If so, that's a very clever way to do it. :)

    BTW, when posting code ...

    attachment.php?attachmentid=78421&d=1297987572

    -Phil
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2011-07-11 09:09
    How about,
    IF ABS X < 10 THEN x=0
    
    ?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-11 10:11
    Sure, that works, as long as the upper and lower limits have the same absolute magnitude. :)

    -Phil
  • VeitchVeitch Posts: 2
    edited 2011-07-11 10:23
    Phil and Tracy thanks for your help.

    I expect there must be several ways to do this.
    I'll use the shorter version suggested.

    Regards
    Veitch
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-11 10:30
    Veitch wrote:
    I'll use the shorter version suggested.
    You can always rest assured that Tracy is the Man when it comes to BASIC Stamp math -- among many other things! Be sure to stop by his website for more insightful Stamp stuff:

    -Phil
Sign In or Register to comment.