hello firned i have a problem in my program for a hatching eggs
the problem that came across is in a specific step the program get frozen and also the serial monitor
like that no data to print or some think that can't let the date to get print
the step that i am blocked is when the buton pressed the time get frozen
this is the code
#include <Adafruit_Sensor.h> // adafrut library for DHT
#include <DHT.h>// dht library
#include <DHT_U.h>// dht lybrari comd
#include <Time.h>
#include <TimeLib.h>
#include <VarSpeedServo.h>// include var speedservo
#include <DS1302RTC.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
VarSpeedServo Myservo; // initial servo varspeed servo
#define DHTPIN 2 // Pin DHT sensor.
#define DHTTYPE DHT11 // DHT 11
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS; // delay for reading the value
DS1302RTC RTC(5, 6, 7);// Set pins: CE, IO, CLK
int temp ;//inisialise variable called temp
int hum ; //inisialasevariable called hum
const int pushbut=4 ;
int val = 0; // push value from pin 2
int lightON = 0;//light status
int NDAY =12 ;
int lastDAY ;
int buzzer=3 ;
int Servopin=9 ;
void printsensorvalue() //function for print sensor value
{
delay(delayMS);// Delay between measurements.
sensors_event_t event; // Get temperature event and print its value.
dht.temperature().getEvent(&event);
lcd.setCursor(5,0);
lcd.print("C");
int temp=(event.temperature);
lcd.setCursor(3,0);
lcd.print(temp);
dht.humidity().getEvent(&event); // Get humidity event and print its value.
lcd.setCursor(2,0);
lcd.print("%");
int hum=(event.relative_humidity);
lcd.setCursor(0,0);
lcd.print(hum);
}
void printTime()
{
// Display time centered on the upper line
lcd.setCursor(7, 0);
print2digits(hour());
lcd.print(":");
print2digits(minute());
lcd.print(":");
print2digits(second());
}
void printdate()
{
// Display date in the lower right corner
lcd.setCursor(5, 1);
lcd.print(" ");
lcd.print(year());
lcd.print("-");
print2digits(month());
lcd.print("-");
print2digits(day());
}
void print2digits(int number) // Output leading zero subroutine
{
if (number >= 0 && number < 10)
{
lcd.write('0');
}
lcd.print(number);
}
void setup()
{
// Setup LCD to 16x2 characters
lcd.begin();
Serial.begin(9600); // Initialize device
dht.begin();// initialize dht
pinMode(pushbut,INPUT_PULLUP);
pinMode(buzzer,OUTPUT);
Serial.println("CANARY");// Print project neame .
lcd.backlight();
lcd.backlight();
lcd.backlight();
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
// Check clock oscillation
lcd.clear();
if (RTC.haltRTC())
lcd.print("Clock stopped!");
else
lcd.print("Clock working.");
// Check write-protection
lcd.setCursor(0, 1);
if (RTC.writeEN())
lcd.print("Write allowed.");
else
lcd.print("Write protected.");
delay ( 2000 );
// Setup Time library
lcd.clear();
lcd.print("RTC Sync");
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() == timeSet)
lcd.print(" Ok!");
else
lcd.print("SVP redemarer ");
delay ( 2000 );
Serial.begin(9600);
// Set time
// hh mm ss dd mm yyyy
setTime(23, 57, 45, 30, 04, 2018); //set the system time to 20:35:30 on 22/12 2015
RTC.set(now()); //set the RTC from the system time
lcd.clear();
}
void loop() // Main loop
{
printsensorvalue();
printTime();
printdate();
// Read and save time and Print on PC
int hh = hour();
int mm = minute();
int ss =second();
Serial.println(mm);
Serial.print(hh);
Serial.print(ss);
int pushed = 0;//push statusint buttonState;
val = digitalRead(pushbut);// read the push button value
if(val == HIGH && lightON == LOW){
pushed = 1-pushed;
delay(100);
}
lightON = val;
if(pushed == HIGH){
if ( temp >= 10)
{// condition of low temp
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Zid skhouniya ");
lcd.backlight();
delay(4000);
lcd.clear();
return(loop);
}
if ( hum>20 )// condition of low humidity
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Zid f routouba");
delay(4000);
lcd.clear();
return(loop);
}
// start principal program
lcd.clear();
lcd.setCursor(0,1);
lcd.print ("START");
delay(2000);
lcd.clear() ;
printsensorvalue();
printTime();
lcd.setCursor(7,1);
lcd.print("ba9i");
lcd.setCursor(13,1);
lcd.print(NDAY);
for ( int NDAY = 12 ; day() != lastDAY ; NDAY-- ) ;
{
printsensorvalue();
printTime();
}
if ( (hh==8) || (hh==10) || (hh==12) || (hh==14) || (hh==16) ||(hh==18) || (hh=20) );// alarm set
{
printsensorvalue();
printTime();
if( (mm==40) && (ss <20) ) //alarm condition
{
printsensorvalue();
printTime();
Myservo.attach(Servopin);
Myservo.write(110,10,true);
Myservo.write(80,10,true);
Myservo.write(110,10,true);
Myservo.write(80,10,true);
Myservo.write(110,10,true);
Myservo.write(90,10,true) ;
Myservo.detach();
}// end condition hour of alarm
printsensorvalue();
printTime();
}
lastDAY = day() ;
// end alarm
if (NDAY=0){
lcd.setCursor(0,1);
lcd.print(NDAY);
return (loop);
// program principal
}
printsensorvalue();
printTime();
lcd.setCursor(7,1);
lcd.print("ba9i");
lcd.setCursor(13,1);
lcd.print(NDAY);
}
else{
}
}
and the step tha iget frozen in is
the serial monitor gets like
23458
234
waiting for your help and thanks in advance ``