How to use "OR"

PostPosted: Fri Apr 04, 2014 10:00 am
I am trying to setup so that my skimmer is off for two periods each day. The following code is what I thought would work, but I guess I am not using the || "OR" operator correctly as I am getting the following compiler errors.

Auto_feed_skimmer_ino.cpp: In function 'void loop()':
Auto_feed_skimmer_ino:166: error: expected primary-expression before '||' token
Auto_feed_skimmer_ino:166: error: expected primary-expression before 'if'
Auto_feed_skimmer_ino:166: error: expected `;' before 'if'

Any suggestions please?


  // Skimmer off during auto feed periods
    
    if ((hour() >= 12) && (hour() < 13)) || if ((hour() >= 18) && (hour() < 19)) // Between 12pm and 1pm OR Between 6pm and 7pm we will disable Port 1
      {
        ReefAngel.Relay.Off(Port1);
      }
        else
      {
        ReefAngel.Relay.On(Port1);
      }

User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Apr 04, 2014 11:01 am
You can't || two if statements like that... try this:

Code: Select all
    if ( ((hour() >= 12) && (hour() < 13)) || ((hour() >= 18) && (hour() < 19)) ) // Between 12pm and 1pm OR Between 6pm and 7pm we will disable Port 1
      {
        ReefAngel.Relay.Off(Port1);
      }
        else
      {
        ReefAngel.Relay.On(Port1);
      }


Also based on your parameters... you could simplify the if to this:

Code: Select all
if ( (hour() == 12) || (hour() == 18) ) // Between 12pm and 1pm OR Between 6pm and 7pm we will disable Port 1
PostPosted: Fri Apr 04, 2014 2:00 pm
Thank's Lee

I used the shorter version, I had forgotten that you can just read the hour value. I will make a note of how to use multiple iIF/OR for the future :oops:
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Apr 04, 2014 3:21 pm
AND and OR are just like the other "conditionals" ==,>,<,>=,<=

Its just a matter of grouping each check you want with parenthesis.

Return to Ask anything here

Who is online

Users browsing this forum: Google [Bot] and 2 guests