Using AND OR operators in combination


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Using AND OR operators in combination

    While I couldn't figure out the logic to all the ('s, I tried it anyway but I get "bad expression" when compiling.

    I have tried it many different ways with no luck. I spoke with Micro-engineering labs as well and they looked at the post and said that the way you describe, is the correct way but they were unsure if your "exact" expression would work.

    Any other thoughts? Could it be because my expressions check a variable as well as a pin state?

    This is the 3 expressions I need to break in to individual expression during an UNTIL function. If confusing, I have seperated the 3 expressions below the example.

    EXAMPLE:
    (Y >= 0) and (BUTTON1 = BUTTONPRESS) OR (Y = 1) AND (BUTTON2 = BUTTONPRESS) OR (Y > 2) AND (BUTTON3 = BUTTONPRESS)

    The 3 expressions seperated by the OR
    (Y >= 0) and (BUTTON1 = BUTTONPRESS)
    (Y = 1) AND (BUTTON2 = BUTTONPRESS)
    (Y > 2) AND (BUTTON3 = BUTTONPRESS)

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Using AND OR operators in combination

    Hi,
    Have you tried
    Code:
    (Y >= 0 and BUTTON1 = BUTTONPRESS) OR (Y = 1 AND BUTTON2 = BUTTONPRESS) OR (Y > 2 AND BUTTON3 = BUTTONPRESS)
    or perhaps
    Code:
    ((Y >= 0) and (BUTTON1 = BUTTONPRESS)) OR ((Y = 1) AND (BUTTON2 = BUTTONPRESS)) OR ((Y > 2) AND (BUTTON3 = BUTTONPRESS))

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Using AND OR operators in combination

    I too am not sure why the first example from shahidali55 didn't work. Seems all the () are in place. Of the 2 from Henrick I think the second will be best.

    Having said that, Even if it works, I am not sure you will save code space using it. It will take a lot of ASM to make that statement.

    Another idea may be to go back to your original post and make the common lines a subroutine. this way the pause1000 will only be coded once and you won't have the complicated until expression.

    Of course you will have to verify by looking at the compiled size.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts