Sometimes the void loop is not necessary to use. That function limits the performance of screens such as ILI9341.
The void loop induces fictitious refresh rates in the graphic performance of the TFT. Some instructions must be executed only at the beginning of a screen cleaning, others must be executed continuously without resulting in annoying flickering or pixel overwriting.
The scheme we can use is as follows:
void funcion()
{
- Instructions that are executed once
while(1) o while(true)
{
- Repetitive or continuous cycle instructions
- To exit it, we can use the TFT touch screen
}
}
In a continuous cycle it is not necessary to use the delay () instruction. I leave you the version that integrates the previous concepts of the main program:
void setup()
{
Serial.begin(115200);
Wire.begin();
bool result = tft.begin();
Serial.print("TFT begin successful: ");
Serial.println(result ? "YES" : "NO");
tft.setRotation(iliRotation90);
tft.fillScreen(ILI9341_BLACK);
// defina a hora inicial aqui:
// DS3231 segundos, minutos, horas, dia, data, mês, ano
// setDS3231time(0,27,6,2,14,9,15); // dia 2 = Segunda-feira
DS3231MP();
}
void loop(){} //Nothing to do here!!!!
void DS3231MP()
{
tft.fillRect(0,0,320,240,ILI9341_WHITE);
while (1)
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
// Data
//gTextArea t1={ 100, 110, 220, 50 };
tft.setTextScale(1);
tft.setFont(Arial_bold_14);
tft.setTextLetterSpacing(5);
tft.setTextColor(ILI9341_BLUE, ILI9341_WHITE);
sprintf(TX, "%02d / %02d / 20%02d", dayOfMonth, month, year);
tft.printAt(TX, 88, 45);
// Hora
//gTextArea t2={ 0, 0, 320, 240 };
tft.setTextScale(2);
tft.setFont(VFDa);
tft.setTextLetterSpacing(4);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
sprintf(TX, "%02d:%02d:%02d", hour, minute,second);
tft.printAt(TX, 5, 100);
//delay(1000);
}
}
I didn't see the jump in the seconds you noticed on your screen.
What version of DS3231 are you using in your setup?. Some link or picture?
Touch wiring:
touch panel (TCLK, TCS, TDIN, TDOUT, IRQ)
URTouch myTouch(6,5,4,3,2);