Coding

Basic / Standard Reef Angel hardware
Post Reply
clw143
Posts: 116
Joined: Fri Jun 21, 2013 8:20 pm
Location: Louisiana

Coding

Post 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);
Piper
Posts: 298
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA

Re: Coding

Post 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.
clw143
Posts: 116
Joined: Fri Jun 21, 2013 8:20 pm
Location: Louisiana

Re: Coding

Post by clw143 »

Yeah that is a possibility, but I'm not understanding why what I am trying to do is not working.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Coding

Post 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.
Post Reply