Hey, i need to print the date it is and calculate the season in order to use a irrigation solenoid valve.
Is there any library that could give the date, and with i could get the season so i can code the necessary instructions to make the valve works?
You can get the date using a Real Time Clock (RTC), a GPS receiver or the Web. Of those the RTC is probably the easiest. Once you have the date it should not be difficult to determine the season if you can describe the start and end of each season
If you do not mind the date/time drifting over a period then you could use the Time library without an external device and set the date/time manually or by setting it to the compile time as long as the Arduino stays powered once it is set
If it can be defined by month, then I fell this is an excellent case for a switch-statement. Switch is easy to understand and gives you freedom to map any month to any season - for example to make winter 4 months long if you need to.
Uses the fallthrough feature of the switch statement.
#include <CurieTime.h>
...
const int WINTER = 1;
const int SPRING = 2;
const int SUMMER = 3;
const int FALL = 4;
const int ERROR = -999;
int season;
int mon;
mon=month(); //from RTC
switch( mon) {
case 12:
case 1:
case 2:
case 3:
season=WINTER;
break;
case 4:
case 5:
season=SPRING;
break;
case 6:
case 7:
case 8:
season=SUMMER;
break;
case 9:
case 10:
case 11:
season=FALL;
break;
default:
// something went wrong, add error handling here
season=-999;
break;
}
//do what ever needs to do on current season
doSeason(season);
Sorry, it is the official meteorological seasons. I figure that's good for an irrigation app. Obviously there are many ways to enhance this program, and many ways to achieve them.
A season may be from early spring to late fall, so it may not relate to calendrical seasons at all. In the end it's about getting the correct date - none of the posted code does that.