Hello all,
I have some code that I need help with. It seems that the subroutine that I created for updating my time and date bar is not functioning correctly. When the subroutine is called from the Setup loop, it runs correctly and populates the data. However when it is called from the main loop, it never executes. I have added a bunch of Serial.prints to try and help troubleshoot it. Here is the code. Please let me know if you need more information or what a possible solution might be. I cant include all the code as its over the maximum allow length for a single post. So here are the subroutine I am calling, the setup loop, and the main loop.
Subroutine being called
//--------------------------------- Time and Date Bar ------------------------------------//
void TimeDateBar() //This needs to be updated once RTC is connected
{
String time, minute, hour,ampm;
myGLCD.setColor (0,0,255);
myGLCD.fillRect (0, 0, 319, 18);
Serial.print ("t.hour entering Sub = ");
Serial.println (t.hour,DEC);
//Pad minute with 0 if necessary
if ((t.min >= 0) && (t.min <= 9))
{
minute = "0" + String(t.min);
}
else
{
minute = String(t.min);
}
Serial.print ("t.min = ");
Serial.println (t.min,DEC);
Serial.print ("minute = ");
Serial.println (minute);
//Figure out hour
if (t.hour == 0)
{
hour = "12";
}
else if (t.hour > 12)
{
hour = String(t.hour - 12);
}
else
{
hour = String(t.hour);
}
Serial.print ("t.hour after adjustment = ");
Serial.println (t.hour,DEC);
Serial.print ("hour after adjustment = ");
Serial.println (hour);
//Determin AM or PM
if (t.hour < 12)
{
ampm = " AM";
}
else
{
ampm = " PM";
}
Serial.print ("ampm after adjustment = ");
Serial.println (ampm);
time = hour + ":" + minute + ampm;
Serial.println ("Time is " + time);
setFont(LARGE,255,255,255,0,0,255);
UpdateTandDBar = 0;
myGLCD.print(time, RIGHT, 1);
myGLCD.print(rtc.getDateStr(FORMAT_LONG,FORMAT_MIDDLEENDIAN,'/'),LEFT,1);
Serial.println ("-----------");
}
And the setup and main loop
//--------------------------------------- Setup ------------------------------------------//
void setup()
{
Serial.begin (9600);
// Initial setup
pinMode(RenaFiltPin, OUTPUT);
pinMode(SunFiltPin, OUTPUT);
pinMode(MainLtPin, OUTPUT);
pinMode(MoonLtPin, OUTPUT);
pinMode(HeaterPin, OUTPUT);
pinMode(CO2Pin, OUTPUT);
pinMode(DosePmp1Pin, OUTPUT);
pinMode(DosePmp2Pin, OUTPUT);
digitalWrite(RenaFiltPin, HIGH);
digitalWrite(SunFiltPin, HIGH);
digitalWrite(MainLtPin, HIGH);
digitalWrite(MoonLtPin, HIGH);
digitalWrite(HeaterPin, HIGH);
digitalWrite(CO2Pin, HIGH);
digitalWrite(DosePmp1Pin, HIGH);
digitalWrite(DosePmp2Pin, HIGH);
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
sensors.begin(); //start up temperature library
// set the resolution to 9 bit
sensors.setResolution(HoodTempSen, 9);
sensors.setResolution(WaterTempSen, 9);
t = rtc.getTime();
checkTemp();
TimeDateBar();
mainScreen(true);
}
//------------------------------------- Main Loop ----------------------------------------//
void loop()
{
unsigned long currentMillis = millis();
if (myTouch.dataAvailable())
{
processMyTouch();
}
if ((currentMillis - prevMillis30 >= 30000) || (UpdateTandDBar)) //Update Time every 30 Seconds
{
prevMillis30 = currentMillis;
//checkTemp();
if (dispScreen == 0)
{
mainScreen(false);
}
// Get data from the DS1307
t = rtc.getTime();
//delay(50);
Serial.println ("Entering Sub");
TimeDateBar();
//checkMainLt();
}
}
Thanks,
Grimm