diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 2358aca..ffaf59d 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -994,6 +994,7 @@ void loop() { unsigned int secondsSunrise = (SunriseHour * 60 * 60) + (SunriseMinute * 60); unsigned int secondsToday = (timeClient.getHours() * 60 * 60) + (timeClient.getMinutes() * 60) + timeClient.getSeconds(); unsigned long currentRuntime = millis(); + byte lightHours; // first we call webserver handle client webserver.handleClient(); @@ -1007,9 +1008,20 @@ void loop() { Serial.println(secondsToday); //Serial.println("yolo"); - // check if secondsToday is larger then secondsSunrise time - if(secondsToday >= secondsSunrise) { + // calculate acutal DayOfGrow + DayOfGrow = int(ceil(float((timeClient.getEpochTime() - GrowStart) / 60 / 60 / 24))); + // decide if we are in Veg or Bloom phase of grow + // when DayOfGrow is larger then DaysVeg we must be in Bloom + if(DayOfGrow > DaysVeg ) { + lightHours = LighthoursBloom; + } else { + lightHours = LighthoursVeg; + } + + // check if secondsToday is larger then secondsSunrise time AND if secondsToday is smaller then the sum of secondsSunrise + seconds of lightHours + if( (secondsToday >= secondsSunrise) && (secondsToday <= ( secondsSunrise + (lightHours * 60 * 60) ) )){ // turn on light + // TODO write a LED control function which takes also takes care of UseLEDrelais analogWrite(PINled, PINled_PWM); } else { // turn off @@ -1287,7 +1299,7 @@ void WEBroot() { body += returnStrDateFromEpoch(GrowStart); body += "
"; body += "Day of Grow: "; - body += int(ceil(float((timeClient.getEpochTime() - GrowStart) / 60 / 60 / 24))) ; + body += DayOfGrow; body += "
"; body += "Soil Moisture: "; body += getSoilmoisture(MoistureSensor_Type);