Page 1 of 1
Lights 8h on/8h off
Posted: Thu Jan 03, 2013 3:01 pm
by symon_say
Hi
I Build and algae scrubber for my tank and would like to set the lights to 8 hrs on and 8 hrs off no matter what time of the day it is, how can i code this in the RA??
Also i just notice that RAgen generates an .ino file, and when i try to save some mods i made arduino ask me to save it in .pde file, is there any difference between this 2 extensions??
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 3:26 pm
by lnevo
I don't think there would be an elegant way to do it per se. Seeing as how there are 24 hours in a day... it might be easier to go 12 hours on / 12 hours off... or 8 hours on, 16 hours off. I'm not the best at time/date math (working on a similar issue for something simpler over here currently..) but there may be some equation.. Good luck.
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 3:42 pm
by rimai
You can do this:
Code: Select all
ReefAngel.Relay.Set(Port1,now()%57600<28800);
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 4:46 pm
by lnevo
Awesome solution

What's the logic for that? Having a tough time understanding how you got to that?
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 4:52 pm
by rimai
now() gives you epoch time, also known as unix time.
It's the number of seconds from a known date... I think 01/01/1970.
So when you modulo with 57600 seconds (number of seconds for 16 hours), it will give you a result that is from 0 to 57599, which represents a cycle of 16 hours.
Since we are interested in an even cycle, we check for less than 28800 seconds (number of seconds for 8 hours). If the cycle is less than 28800 seconds, we want lights on and if not, we want lights off.
Lights 8h on/8h off
Posted: Thu Jan 03, 2013 5:24 pm
by lnevo
I got it...very cool.
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 6:16 pm
by symon_say
Nice one Roberto, thanks a lot.
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 6:53 pm
by symon_say
The should have an extra ), this is the code:
Code: Select all
ReefAngel.Relay.Set(Port1,now()%57600<28800);
Re: Lights 8h on/8h off
Posted: Thu Jan 03, 2013 7:46 pm
by rimai
Thanks...

I corrected the original too.