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??
Lights 8h on/8h off
-
symon_say
- Posts: 118
- Joined: Sun Oct 09, 2011 6:04 am
- Location: Dominican Republic
- Contact:
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Lights 8h on/8h off
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
You can do this:
Code: Select all
ReefAngel.Relay.Set(Port1,now()%57600<28800);
Roberto.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Lights 8h on/8h off
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
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.
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.
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
-
symon_say
- Posts: 118
- Joined: Sun Oct 09, 2011 6:04 am
- Location: Dominican Republic
- Contact:
-
symon_say
- Posts: 118
- Joined: Sun Oct 09, 2011 6:04 am
- Location: Dominican Republic
- Contact:
Re: Lights 8h on/8h off
The should have an extra ), this is the code:
Code: Select all
ReefAngel.Relay.Set(Port1,now()%57600<28800);-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm