Hi;
I'm French, please excuse by bad English.
In my project I want to switch on/switch off a light including the photoperiod.
To do that I great bidimentionnal array call photoperiode[367][3] (365 days including 2 others particular data) and [3] for time switch on, time switch off, and during.
As this arry are very big I put in Flach memories via PROGMEM. ( May be you can help me to found another way)
A function calculate the day number since 1st january (DN)
I witch to call the switch on time storage in my arry trought this function
#include <Wire.h>
#include <RTClib.h>
#include <DHT22.h>
#include <LiquidCrystal_I2C.h>
#include <avr/pgmspace.h>
RTC_DS1307 RTC;
prog_int16_t Photoperiode[367][3] PROGMEM ={
{810,1810,1000},
{810,1810,1000},
{551,2158,1607},
{551,2159,1608},
{550,2159,1609},
{550,2200,1610},
{549,2201,1612},
{549,2201,1612},
{549,2202,1613},
{549,2203,1614},
{549,2203,1614},
{549,2204,1615},
{549,2204,1615},
{549,2205,1616},
{549,2205,1616},
{549,2205,1616},
{549,2205,1616},
{549,2206,1617},
{549,2206,1617},
{549,2205,1616},
{549,2205,1616},
{549,2205,1616},
{549,2205,1616},
{549,2204,1615},
{549,2204,1615},
{549,2203,1614},
{549,2203,1614},
{549,2202,1613},
{549,2201,1612},
{549,2201,1612},
{550,2200,1610},
{550,2159,1609},
{551,2159,1608},
{551,2158,1607},
{551,2157,1606},
{552,2156,1604},
{553,2155,1602},
{553,2154,1601},
{554,2153,1559},
{555,2152,1557},
{555,2151,1556},
{556,2150,1554},
{557,2149,1552},
{558,2148,1550},
{559,2147,1548},
{600,2146,1546},
{601,2144,1543},
{602,2143,1541},
{603,2142,1539},
{604,2141,1537},
{605,2139,1534},
{606,2138,1532},
{607,2137,1530},
{609,2135,1526},
{610,2134,1524},
{611,2133,1522},
{613,2131,1518},
{614,2130,1516},
{615,2129,1514},
{617,2127,1510},
{618,2126,1508},
{620,2124,1504},
{621,2123,1502},
{623,2121,1458},
{625,2120,1455},
{626,2118,1452},
{628,2117,1449},
{630,2115,1445},
{631,2114,1443},
{633,2112,1439},
{635,2111,1436},
{636,2109,1433},
{638,2108,1430},
{640,2106,1426},
{642,2105,1423},
{644,2103,1419},
{646,2102,1416},
{647,2100,1413},
{649,2059,1410},
{651,2057,1406},
{653,2056,1403},
{655,2054,1359},
{657,2053,1356},
{659,2051,1352},
{701,2050,1349},
{703,2048,1345},
{705,2047,1342},
{707,2045,1338},
{709,2044,1335},
{711,2042,1331},
{713,2041,1328},
{715,2039,1324},
{717,2038,1321},
{719,2036,1317},
{722,2034,1312},
{724,2033,1309},
{726,2031,1305},
{728,2030,1302},
{730,2028,1258},
{732,2027,1255},
{634,1925,1251},
{636,1924,1248},
{638,1922,1244},
{641,1921,1240},
{643,1919,1236},
{645,1918,1233},
{647,1916,1229},
{649,1915,1226},
{651,1913,1222},
{653,1911,1218},
{656,1910,1214},
{658,1908,1210},
{700,1907,1207},
{702,1905,1203},
{704,1904,1200},
{706,1902,1156},
{708,1901,1153},
{711,1859,1148},
{713,1857,1144},
{715,1856,1141},
{717,1854,1137},
{719,1853,1134},
{721,1851,1130},
{723,1850,1127},
{725,1848,1123},
{727,1846,1119},
{729,1845,1116},
{731,1843,1112}
}; ////////troncate array
int HeureStart =1830;
int HeureStop =900;
// Variable
int DN; //Returns the number of day in the year
int WN;
// DHT22
// Data wire is plugged into port 7 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define DHT22_PIN 7
// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);
///////////////////////////////////////////// SETUP ////////////////////////////////
void setup()
{ Serial.begin(9600);
Wire.begin();
RTC.begin();
}
///////////////////////////////////////////// LOOP ////////////////////////////////
void loop()
{
DateTime now =RTC.now();// lecture de la date sur le DS1307
day=now.day();
month=now.month();
year=now.year();
hour=now.hour();
minute=now.minute();
dayOfWeek=now.dayOfWeek();
ActualTime=(hour * 100) + minute;
DayWeekNumber(now.year(),now.month(),now.day(),now.dayOfWeek()); // calcule de DN et DW nb jours de l'annee
Serial.print("Day #");
Serial.print(DN);
Serial.print(" at week # ");
Serial.print(WN);
Serial.print(" of ");
Serial.println(year);
ClimateData(); // mesure de la Temperature
StockageClimate ();
displayData();
Serial.print("Days ");
Serial.println(DN);
Serial.print("Current Time : ");
Serial.println(ActualTime);
Serial.print("Switch on Time (i): ");
int i = 118;
Serial.println(Photoperiode[i][0]);
Serial.print("Switch on Time (DN): ");
Serial.println(Photoperiode[DN][0]);
Serial.print("Switch off Time : ");
Serial.println(Photoperiode[118][1]);
delay(2000);
Serial.println("##########################");
}
void DayWeekNumber(unsigned int y, unsigned int m, unsigned int d, unsigned int w)
{
int days[]={0,31,59,90,120,151,181,212,243,273,304,334}; // Number of days at the beginning of the month in a not leap year.
//Start to calculate the number of day
if (m==1 || m==2)
{
DN = days[(m-1)]+d; //for any type of year, it calculate the number of days for January or february
}
// Now, try to calculate for the other months
else if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
{ //those are the conditions to have a leap year
DN = days[(m-1)]+d+1; // if leap year, calculate in the same way but increasing one day
}
else
{
DN = days[(m-1)]+d; //if not a leap year, calculate in the normal way, such as January or February
}
// Now start to calculate Week number
if (w==0)
{
WN = (DN-7+10)/7; //if it is sunday (time library returns 0)
}
else
{
WN = (DN-w+10)/7; // for the other days of week
}
}
///////////////////////////////////////////////////
Ca sort:
Days 118
Current Time : 1409
Switch on Time (i): 636
Switch on Time (DN): 273
Switch off Time : 2109
##########################
So My probleme is:
When I used i= 118 I have the good value 636 (read 6h36).
But When I used the function DN (wich return me 118) the value is bab one.
can you explain that ?
Best reagard
Damien