Offline
Newbie
Karma: 0
Posts: 19
|
 |
« on: April 16, 2012, 07:20:44 pm » |
hello Setting up a reef tank and i have most code i think i need...? issues in my head with how seasons need to be read from rtc. i have included the file so you can see how its actually gonna work. Shortcuts would be awesome to learn..
if((month=<6 && dayOfWeek=<19)||(month=>3 && dayOfWeek=<20)||(month=>3 && month=<5)) else if // spring { } elseif ((month=<9 && dayOfWeek=<21)||(month=>6 && dayOfWeek=<20)||(month=>7 && month=<8)) else if // summer { } elseif ((month=<12 && dayOfWeek=<20)||(month=>9 && dayOfWeek=<22)||(month=>10 && month=<11)) else if // fall { } elseif ((month=<3 && dayOfWeek=<19)||(month=>12 && dayOfWeek=<21)||(month=>1 && month=<2)) else if // winter { }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #1 on: April 16, 2012, 08:43:51 pm » |
Even assuming you are in the northern hemisphere, your code won't work. For example, for Jan 1st (month ==1, dayOfWeek == 1) it will determine it's spring (first if condition is true).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 19
|
 |
« Reply #2 on: April 16, 2012, 08:48:51 pm » |
Call me the cat but it should only run as code directs it should it not!?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #3 on: April 16, 2012, 09:03:53 pm » |
if((month=<6 && dayOfWeek=<19)||(month=>3 && dayOfWeek=<20)||(month=>3 && month=<5)) else if // spring The condition in the if statement is true when month==1 and dayOfWeek==1, isn't it? At the end, you make the comment "spring", so I assume you are going to execute something specific to spring, are you not?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 19
|
 |
« Reply #4 on: April 16, 2012, 09:46:37 pm » |
How would u suppose or direct me in a direction I need to go so I can get the seasons effect.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 19
|
 |
« Reply #5 on: April 16, 2012, 10:34:48 pm » |
How about a switch case statement, if(months&&date) good switch
Case1 spring
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #6 on: April 16, 2012, 10:48:51 pm » |
Something like: switch (month) { case 1: // January case 2: // and February season = summer; break;
case 3: // March if (day >= 21) season = autumn; else season = summer; break;
// ... and so on } // end of switch
I live in the southern hemisphere BTW, which is why it is autumn right now.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 10
Posts: 871
|
 |
« Reply #7 on: April 17, 2012, 12:30:30 am » |
one thing about me is (and people may come to notice...) i really hate to over-complicate ANYTHING eg if it's not needed or an alternative is there take it anything reduce your memory usage or binary size.
but, and my understanding could be way off here.. but.. am I right in understanding you want certain actions depending on the time of year? eg if it's summer more daylight therefor the the lights come on at different times of the day, so the RTC is read and through a series of calculations you know exactly when to switch on and off the lights and other things like pumps and stuff.
if so?.. why an RTC at all?
run a cable (or invest in another small arduino with 2 wireless modules) to a window and on the end of the cable attach a photo resistor, feed the other end into your analogue in and read the values appropriately, or use another arduino to relay back the information if you want a clean setup... now when it "goes dark" or cloudy or a storm approaches and it's dark at 3pm, you don't need to guess what's going on, you actually have real world data coming in, based on how much light there is, you switch the lights on or off.
Now having said all that i could be completely wrong and you have to use the RTC and you can't use say a Temperature Sensor and Light Sensor to fully automate it.. imagine if street lamps only came on at a certain times based on the year date and time, no to consistently get it come on as it goes dark be the middle of the day or night time, a light sensor is used.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #8 on: April 17, 2012, 12:41:14 am » |
Yes, good idea.
Another approach would be to take the date, turn it into a Julian date (ie. day of year) ... I think there are quite a few short algorithms for that. Then simply do a straight compare. There will only be 4 break points then.
And here's another idea ... by reading in sunlight you can deduce the season. For example, very short days ... winter.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 10
Posts: 871
|
 |
« Reply #9 on: April 17, 2012, 01:39:28 am » |
Yes, good idea.
Another approach would be to take the date, turn it into a Julian date (ie. day of year) ... I think there are quite a few short algorithms for that. Then simply do a straight compare. There will only be 4 break points then.
And here's another idea ... by reading in sunlight you can deduce the season. For example, very short days ... winter.
yeah, store how much light comes in and at the end of the day store it onto the eeprom, to get number hours of light, like it, very short days = nuclear winter (or just plain old winter) 
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #10 on: April 17, 2012, 01:49:55 am » |
The sketch posted already calculates the Julian date to get the moon phase.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #11 on: April 17, 2012, 01:50:45 am » |
Problem solved, then.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 19
|
 |
« Reply #12 on: April 17, 2012, 05:03:43 am » |
this was how i was gonna do the lights and fan but in my research i think there could be another way . and yes i im in the northern hemisphere
if(hours == 5 && minutes == 0 && !ledOff)//actinics off if(hours == 4 && minutes == 55 && !fluores1On)//fluorescents off if(hours == 9 && minutes == 0 && !mhOn)//metal halide on if(hours == 9 && minutes == 15 && !fanOn)//cooling fan on for metal halide if(hours == 3 && minutes == 0 && !mhoff)//metal halide off if(hours == 3 && minutes == 15 && !fanOff)//fan off if(hours == 19 && minutes == 0 && !fluores1Off)//fluorescents off if(hours == 18 && minutes == 55 && !ledOn)//actinics on { mhOn = true; fluores1On = true; fluores2On = true; fanOn = true; ledOn = true; mhoff = true; fluores1Off = true; fluores2Off = true; fanOff = true; ledOff = true;
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #13 on: April 17, 2012, 06:14:37 am » |
fanOn = true; ledOn = true; ... fanOff = true; ledOff = true;
I honestly don't know what you are trying to do here. Is the fan both on and off? And the LED? How does that even work?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 19
|
 |
« Reply #14 on: April 17, 2012, 07:16:01 am » |
I knew I was gonna hear that.. that was an older sketch. I will be rewriting as If(times---------eg------!fanOn); Else = !fanOff;
Sorry but most of typing is done by phone
|
|
|
|
|
Logged
|
|
|
|
|
|