Go Down

Topic: Salt Reef seasons IF Then Confusion!? (Read 2 times) previous topic - next topic

djjester611

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
{
}

florinc

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).


djjester611

Call me the cat but it should only run as code directs it should it not!?

florinc

Quote
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?

djjester611

How would u suppose or direct me in a direction I need to go so I can get the seasons effect.

djjester611

How about a switch case statement,  if(months&&date) good switch

Case1 spring

Nick Gammon

Something like:

Code: [Select]

 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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

cjdelphi

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. 


Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

cjdelphi


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) :D

dxw00d

The sketch posted already calculates the Julian date to get the moon phase.

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

djjester611

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;
       

Nick Gammon

Code: [Select]

        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?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

djjester611

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

Go Up