Page 1 of 1

Coding

Posted: Sun Jan 24, 2021 11:07 pm
by clw143
Anyone shine some light on why this does not work?

Code: Select all

long SetTime;
long RiseTime;   

//Fuge Light on 1 hour before sunset and off 1 hour after sunrise
if (now()>(SetTime - 3600) || now()<(RiseTime + 3600)) ReefAngel.Relay.On(Port6);
else ReefAngel.Relay.Off(Port6);

SetTime = (InternalMemory.StdLightsOnHour_read() * 60 * 60) + (InternalMemory.StdLightsOnMinute_read() * 60);
RiseTime = (InternalMemory.StdLightsOffHour_read() * 60 * 60) + (InternalMemory.StdLightsOffMinute_read() * 60);

Re: Coding

Posted: Mon Jan 25, 2021 8:23 am
by Piper
Try using hour() instead of now().

Code: Select all

    //Fuge Light on 1 hour before sunset and off 1 hour after sunrise
    if (hour() >= (InternalMemory.StdLightsOnHour_read() - 1) && hour() <= (InternalMemory.StdLightsOffHour_read() + 1)) {
        ReefAngel.Relay.On(Port6);
    } else {
        ReefAngel.Relay.Off(Port6);
    }
This compiles but I have not tested it.

Re: Coding

Posted: Mon Jan 25, 2021 9:50 pm
by clw143
Yeah that is a possibility, but I'm not understanding why what I am trying to do is not working.

Re: Coding

Posted: Tue Jan 26, 2021 6:54 am
by binder
Looking at your code, you are not initializing SetTime and RiseTime before you try to use them. You have:

Code: Select all

long SetTime;
long RiseTime;
Then, the next statement you are trying to use those variables in an IF statement. The values stored in them are "undefined" or whatever else the system decided to put in them when initializing. You need to move the initializing code segment before you use the variables.

Code: Select all

long SetTime = (InternalMemory.StdLightsOnHour_read() * 60 * 60) + (InternalMemory.StdLightsOnMinute_read() * 60);
long RiseTime = (InternalMemory.StdLightsOffHour_read() * 60 * 60) + (InternalMemory.StdLightsOffMinute_read() * 60);

//Fuge Light on 1 hour before sunset and off 1 hour after sunrise
if (now()>(SetTime - 3600) || now()<(RiseTime + 3600)) ReefAngel.Relay.On(Port6);
else ReefAngel.Relay.Off(Port6);
This should work now.