How to use "OR"

Post Reply
Sebyte

How to use "OR"

Post by Sebyte »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: How to use "OR"

Post by lnevo »

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
Sebyte

Re: How to use "OR"

Post by Sebyte »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: How to use "OR"

Post by lnevo »

AND and OR are just like the other "conditionals" ==,>,<,>=,<=

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