Lights 8h on/8h off

Do you have a question on how to do something.
Ask in here.
Post Reply
symon_say
Posts: 118
Joined: Sun Oct 09, 2011 6:04 am
Location: Dominican Republic
Contact:

Lights 8h on/8h off

Post 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??
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Lights 8h on/8h off

Post 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.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Lights 8h on/8h off

Post by rimai »

You can do this:

Code: Select all

ReefAngel.Relay.Set(Port1,now()%57600<28800);
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Lights 8h on/8h off

Post by lnevo »

Awesome solution :) What's the logic for that? Having a tough time understanding how you got to that?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Lights 8h on/8h off

Post 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.
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Lights 8h on/8h off

Post by lnevo »

I got it...very cool.
symon_say
Posts: 118
Joined: Sun Oct 09, 2011 6:04 am
Location: Dominican Republic
Contact:

Re: Lights 8h on/8h off

Post by symon_say »

Nice one Roberto, thanks a lot.
Image
symon_say
Posts: 118
Joined: Sun Oct 09, 2011 6:04 am
Location: Dominican Republic
Contact:

Re: Lights 8h on/8h off

Post by symon_say »

The should have an extra ), this is the code:

Code: Select all

ReefAngel.Relay.Set(Port1,now()%57600<28800);
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Lights 8h on/8h off

Post by rimai »

Thanks... :)
I corrected the original too.
Roberto.
Post Reply