Code partialy stops working after a couple seconds

Hi,

im currently working on a controller for terrariums / aquariums etc. with touchscreen and several sensors ... currently there is an AC sensor, a DHT and a RTC connected and as display im using a touchscreen ... as you can see in the code below its a bit chaotic still :wink:

i have hardcoded the first few lines just to display the date in bottom left corner and the current time in bottom right, these keep updating no problem ...

but as soon as i use the struct to redraw certain elements on update (or timed currently) it just stops working after a while and i can not figure out why ... at first i thought it was the variable size string at the end of the struct, but it also has the same effect when i use a char [4] in its place just that i lose flexibility ...

i also had it running on my RTC at first with seconds, but i figured maybe the RTC fails and switched to millis ...

please no scolding for the stupid variable declarations, i will eventualy pull them all out of the loop and clean up, but scrolling up and down the editor when testing things is not my thing :wink:

does anyone have any suggestions why it stops drawing these last 2 elements (AC and DHT)?

Thanks alot for your help!

"please no scolding for the stupid variable declarations"

No chance of this as there is no sketch attached.

.

first half of code (its too large and i can only make 1 post every 5 min ><):

#include <memorysaver.h>
#include <UTFT.h>
#include <URTouch.h>
#include <SD.h>                    //SD card library
#include <Wire.h>  
#include <SPI.h>
#include <DHT.h>
#include <Time.h>
#include <DS1307RTC.h>


#define DHTPIN A0 
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

UTFT myGLCD(ITDB32S,38,39,40,41);  //pins used for TFT
URTouch  myTouch( 6, 5, 4, 3, 2);
extern uint8_t BigFont[];          //Which fonts to use...
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];


float gfLineVoltage = 235.0f;               // typical effective Voltage in Germany
float gfACS712_Factor = 75.76f;              // use 50.0f for 20A version, 75.76f for 30A version; 27.03f for 5A version
unsigned long gulSamplePeriod_us = 100000;  // 100ms is 5 cycles at 50Hz and 6 cycles at 60Hz
int giADCOffset = 512;                      // initial digital zero of the arduino input from ACS712

int ttdht = 0;
int ttcls = 0;
int ttac = 0;
int touchx;
int touchy;

File myFile;

// START AC CURRENT SENSOR //  
float ACSensorPoll () {
  float fCurrentRMS = 0;
  long lNoSamples=0;
  long lCurrentSumSQ = 0;
  long lCurrentSum=0;
  // set-up ADC
  ADCSRA = 0x87;  // turn on adc, adc-freq = 1/128 of CPU ; keep in min: adc converseion takes 13 ADC clock cycles
  ADMUX = 0x43;   // internal 5V reference
  // 1st sample is slower due to datasheet - so we spoil it
  ADCSRA |= (1 << ADSC);
  while (!(ADCSRA & 0x10));
  // sample loop - with inital parameters, we will get approx 800 values in 100ms
  unsigned long ulEndMicros = micros()+gulSamplePeriod_us;
  while(micros()<ulEndMicros)
  {
    // start sampling and wait for result
    ADCSRA |= (1 << ADSC);
    while (!(ADCSRA & 0x10));
    // make sure that we read ADCL 1st
    long lValue = ADCL;
    lValue += (ADCH << 8);
    lValue -= giADCOffset;
    lCurrentSum += lValue;
    lCurrentSumSQ += lValue*lValue;
    lNoSamples++;
  }
  // stop sampling
  ADCSRA = 0x00;
  if (lNoSamples>0)  // if no samples, micros did run over
  {  
    // correct quadradic current sum for offset: Sum((i(t)+o)^2) = Sum(i(t)^2) + 2*o*Sum(i(t)) + o^2*NoSamples
    // sum should be zero as we have sampled 5 cycles at 50Hz (or 6 at 60Hz)
    float fOffset = (float)lCurrentSum/lNoSamples;
    lCurrentSumSQ -= 2*fOffset*lCurrentSum + fOffset*fOffset*lNoSamples;
    if (lCurrentSumSQ<0) {lCurrentSumSQ=0;} // avoid NaN due to round-off effects
    fCurrentRMS = sqrtf((float)lCurrentSumSQ/(float)lNoSamples) * gfACS712_Factor * gfLineVoltage / 1024;
    // correct offset for next round
    giADCOffset=(int)(giADCOffset+fOffset+0.5f);
  }
    return fCurrentRMS;
}
// END AC CURRENT SENSOR //  


struct Element {
 int pageID;
 int sX; //start X
 int sY; //start Y
 int eX; //end X
 int eY; //end Y
 int radius; //for round elements
 int font; //1 smallfont, 2 bigfont, 3 sevensegnumfont
 int type; //  1 = button, 2 = rectangle, 3 = round rectangle, 4 = text box, 5 = circle
 int colorR; //font-color
 int colorG;
 int colorB;
 int BGcolorR; //background color for text or fill color for objects
 int BGcolorG;
 int BGcolorB;
 int BordercolorR; //border color
 int BordercolorG;
 int BordercolorB;
 int ABordercolorR; //border color when pressed
 int ABordercolorG;
 int ABordercolorB;
 bool redraw; 
 String label; //for buttons or text display in a box
};

Element pageElements[] = {
 { //element 1
 1, //page ID
 11,
 22,
 110,
 40,
  123,
 1,
 4,
 255, //r
 1, //g
 2,//b
 3,//r
 255, //g
 0,//b
 5,//r
 6,//g
 7,//b
 8,
 9,
 88,
 1,
 "Button Label"
 },
 //element 2
{
  1, //page ID
 11,
 60,
 110,
 88,
 123,
 1,
 4,
 0, //r
 255, //g
 2,//b
 255,//r
 0, //g
 0,//b
 0,//r
 0,//g
 255,//b
 8,
 9,
 88,
 1,
 "Button 2"
 },
 //element 3
{
  1, //page ID
 11,
 90,
 110,
 114,
 123,
 1,
 4,
 0, //r
 255, //g
 2,//b
 255,//r
 0, //g
 0,//b
 0,//r
 0,//g
 255,//b
 8,
 9,
 88,
 1,
 "Button 3"
 }
};
void DrawCircle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
     myGLCD.drawCircle (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].radius);
}

void DrawRectangle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
     myGLCD.drawRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void DrawRoundRectangle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
     myGLCD.drawRoundRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void FillCircle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
     myGLCD.fillCircle (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].radius);
}

void FillRectangle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
     myGLCD.fillRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void FillRoundRectangle (int elementID) {
    myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
    myGLCD.fillRoundRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void DrawButton (int elementID) {
     FillRoundRectangle(elementID);
     DrawRoundRectangle(elementID);
     DrawTextBox(elementID);
}
void SetFont (int font){
      switch (font){
      case 1:
      myGLCD.setFont(SmallFont);
      break;
      case 2:
      myGLCD.setFont(BigFont);
      break;
      case 3:
      myGLCD.setFont(SevenSegNumFont);
      break;
     }  
}

void DrawTextBox (int elementID) {
     myGLCD.setColor(pageElements[elementID].colorR, pageElements[elementID].colorG, pageElements[elementID].colorB);
     myGLCD.setBackColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
     SetFont(pageElements[elementID].font);
     myGLCD.print(pageElements[elementID].label, pageElements[elementID].sX+3, pageElements[elementID].sY+3);   
}

void DrawDone (int elementID) {
      pageElements[elementID].redraw = 0;
}

void DrawPage (int pageID) {
   for(int i=0; i<= 3; i = i +1){
   if (pageID == pageElements[i].pageID) {
     if (pageElements[i].redraw == 1){
      switch(pageElements[i].type){ //  1 = button, 2 = rectangle, 3 = round rectangle, 4 = text box, 5 = circle, 6 = filled rectangle, 7 = filled round rectangle, 8 = filled circle
       case 1:
       DrawButton(i);
       DrawDone(i);
       break;
       case 2:
       DrawRectangle(i);
       DrawDone(i);
       break;
       case 3:
       DrawRoundRectangle(i);
       DrawDone(i);
       break;
       case 4:
       DrawTextBox(i);
       DrawDone(i);
       break;
       case 5:
       DrawCircle(i);
       DrawDone(i);
       break;
       case 6:
       FillRectangle(i);
       DrawDone(i);
       break;
       case 7:
       FillRoundRectangle(i);
       DrawDone(i);
       break;
       case 8:
       FillCircle(i);
       DrawDone(i);
       break;
       }
     }
   }
  }
}

void setup() {
 Serial.begin(9600);
 pinMode(46, OUTPUT);
 pinMode(A0, INPUT);
 pinMode(A1, INPUT);
 pinMode(A2, INPUT);
 pinMode(A3, INPUT);
 
 dht.begin();
 myGLCD.InitLCD(LANDSCAPE);      //LANDSCAPE or PORTRAIT
 myGLCD.clrScr();
 myTouch.InitTouch(LANDSCAPE);
 myTouch.setPrecision(PREC_MEDIUM);
 SD.begin(53);
}

second half of code (i also only can edit a post every 5 min! lol):

void loop() {
  
 
  digitalWrite(46, LOW);
  char b[2];
  String str;
  String str2;
  String str3;
  String strtest;
  tmElements_t tm;
  if (RTC.read(tm)) {
    int hour=tm.Hour;
    if (hour < 10) {
      str="0"+String(hour);
    }
    else {
      str=String(hour);
    }
    str.toCharArray(b,2);
    int minute=tm.Minute;
    if (minute < 10) {
      str2="0"+String(minute);
    }
    else {
      str2=String(minute);
    }
    str2.toCharArray(b,2);  
    int second=tm.Second;
    if (second < 10) {
      str3="0"+String(second);
    }
    else {
      str3=String(second);
    }
    str3.toCharArray(b,2);
    myGLCD.setColor(0, 255, 0);
    myGLCD.setBackColor(0, 0, 0);
    myGLCD.print(str +":"+ str2 + ":" + str3, RIGHT , 225); //print time bottom right corner
  }
  
  int day=tm.Day;
  if (day < 10) {
    str="0"+String(day);
  }
  else {
    str=String(day);
  }
  str.toCharArray(b,2);
  int month=tm.Month;
  if (month < 10) {
    str2="0"+String(month);
  }
  else {
    str2=String(month);
  }
  str2.toCharArray(b,2);  
  int year=tmYearToCalendar(tm.Year);
  str3=String(year);
  
  str3.toCharArray(b,2);
  
  myGLCD.print(str +"."+ str2 + "." + str3, LEFT , 225); //print date bottom left corner

  if (ttdht == 0) { ttdht = millis(); }
  if (ttdht + 5000 <= millis()) {
  
  int temp=dht.readTemperature();
  str=String(temp);
  
  pageElements[1].label = str;
  pageElements[1].redraw = 1;
  
 
  ttdht = millis();
  } 
  
  if (ttac == 0) { ttac = millis(); }
  if (ttac + 1000 <= millis()) {

  pageElements[2].label = ACSensorPoll ();
  pageElements[2].redraw = 1;
  ttac = millis();
  
  }  
  
  DrawPage(1);
  
  
}

Their is a good chance using String is messing up your memory.
Use character arrays instead.

You should use 'subtraction' when you use millis() in timing code.

.

i tried both already, thats why there are the "toCharArray" remnants still in there ... and before this version i actualy used substraction :wink:

 if ((millis() - ttac) >= 1000)

both things did not change the outcome, it still randomly stops updating the struct items where as the hardcoded date and time keep running ...

Clean up and layout your code before posting!

Mark

if (ttdht == 0) { ttdht = millis(); }
if (ttdht + 5000 <= millis()) {

What's this?

.

void loop() {
  
 
  digitalWrite(46, LOW); //turn on relay


//Date and Time - reading RTC and displaying values on LCD
  tmElements_t tm;
  if (RTC.read(tm)) {
    int hour=tm.Hour;
    if (hour < 10) {
      str="0"+String(hour);
    }
    else {
      str=String(hour);
    }
    str.toCharArray(b,2);
    int minute=tm.Minute;
    if (minute < 10) {
      str2="0"+String(minute);
    }
    else {
      str2=String(minute);
    }
    str2.toCharArray(b,2);  
    int second=tm.Second;
    if (second < 10) {
      str3="0"+String(second);
    }
    else {
      str3=String(second);
    }
    myGLCD.setColor(0, 255, 0);
    myGLCD.setBackColor(0, 0, 0);
    myGLCD.print(str +":"+ str2 + ":" + str3, RIGHT , 225); //print time bottom right corner
  }
  
  int day=tm.Day;
  if (day < 10) {
    str="0"+String(day);
  }
  else {
    str=String(day);
  }
  str.toCharArray(b,2);
  int month=tm.Month;
  if (month < 10) {
    str2="0"+String(month);
  }
  else {
    str2=String(month);
  }
  int year=tmYearToCalendar(tm.Year);
  str3=String(year);
  
  myGLCD.print(str +"."+ str2 + "." + str3, LEFT , 225); //print date bottom left corner
//END Date and Time

//Update DHT every 5 seconds
  if (ttdht == 0) { ttdht = millis(); }
  if ((millis() - ttdht) >= 5000) {
  
  int temp=dht.readTemperature();
  str=String(temp);
  str.toCharArray(pageElements[1].label,6);
  pageElements[1].redraw = 1;
  ttdht = millis();
  } 
//END Update DHT

//Update AC Sensor every 1 second
  if (ttac == 0) { ttac = millis(); }
  if ((millis() - ttac) >= 1000) {
  str= ACSensorPoll();
  str.toCharArray(pageElements[2].label,6);
  pageElements[2].redraw = 1;
  ttac = millis();
  
  }  
//END Update AC

//Draw Pages
  DrawPage(1); //Draw Page 1
//END Draw Pages  
  
}

cleaned up the loop

#include <memorysaver.h>
#include <UTFT.h>
#include <URTouch.h>
#include <SD.h>                    //SD card library
#include <Wire.h>  
#include <SPI.h>
#include <DHT.h>
#include <Time.h>
#include <DS1307RTC.h>


#define DHTPIN A0 
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

UTFT myGLCD(ITDB32S,38,39,40,41);  //pins used for TFT
URTouch  myTouch( 6, 5, 4, 3, 2);
extern uint8_t BigFont[];          //Which fonts to use...
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];


float gfLineVoltage = 235.0f;               // typical effective Voltage in Germany
float gfACS712_Factor = 75.76f;              // use 50.0f for 20A version, 75.76f for 30A version; 27.03f for 5A version
unsigned long gulSamplePeriod_us = 100000;  // 100ms is 5 cycles at 50Hz and 6 cycles at 60Hz
int giADCOffset = 512;                      // initial digital zero of the arduino input from ACS712

int ttdht = 0;
int ttac = 0;
int touchx;
int touchy;
char b[6];
String str;
String str2;
String str3;
  
struct Element {
 int pageID;
 int sX; //start X
 int sY; //start Y
 int eX; //end X
 int eY; //end Y
 int radius; //for round elements
 int font; //1 smallfont, 2 bigfont, 3 sevensegnumfont
 int type; //  1 = button, 2 = rectangle, 3 = round rectangle, 4 = text box, 5 = circle
 int colorR; //font-color
 int colorG;
 int colorB;
 int BGcolorR; //background color for text or fill color for objects
 int BGcolorG;
 int BGcolorB;
 int BordercolorR; //border color
 int BordercolorG;
 int BordercolorB;
 int ABordercolorR; //border color when pressed
 int ABordercolorG;
 int ABordercolorB;
 bool redraw; 
 char label[6]; //for buttons or text display in a box
};

Element pageElements[] = {
 { //element 1
 1, //page ID
 11,
 22,
 110,
 40,
  123,
 1,
 4,
 255, //r
 1, //g
 2,//b
 3,//r
 255, //g
 0,//b
 5,//r
 6,//g
 7,//b
 8,
 9,
 88,
 1,
 'But1'
 },
 //element 2
{
  1, //page ID
 11,
 60,
 110,
 88,
 123,
 1,
 4,
 0, //r
 255, //g
 2,//b
 255,//r
 0, //g
 0,//b
 0,//r
 0,//g
 255,//b
 8,
 9,
 88,
 1,
 'But2'
 },
 //element 3
{
  1, //page ID
 11,
 90,
 110,
 114,
 123,
 1,
 4,
 0, //r
 255, //g
 2,//b
 255,//r
 0, //g
 0,//b
 0,//r
 0,//g
 255,//b
 8,
 9,
 88,
 1,
 'But3'
 }
};

// START AC CURRENT SENSOR //  
float ACSensorPoll () {
  float fCurrentRMS = 0;
  long lNoSamples=0;
  long lCurrentSumSQ = 0;
  long lCurrentSum=0;
  // set-up ADC
  ADCSRA = 0x87;  // turn on adc, adc-freq = 1/128 of CPU ; keep in min: adc converseion takes 13 ADC clock cycles
  ADMUX = 0x43;   // internal 5V reference
  // 1st sample is slower due to datasheet - so we spoil it
  ADCSRA |= (1 << ADSC);
  while (!(ADCSRA & 0x10));
  // sample loop - with inital parameters, we will get approx 800 values in 100ms
  unsigned long ulEndMicros = micros()+gulSamplePeriod_us;
  while(micros()<ulEndMicros)
  {
    // start sampling and wait for result
    ADCSRA |= (1 << ADSC);
    while (!(ADCSRA & 0x10));
    // make sure that we read ADCL 1st
    long lValue = ADCL;
    lValue += (ADCH << 8);
    lValue -= giADCOffset;
    lCurrentSum += lValue;
    lCurrentSumSQ += lValue*lValue;
    lNoSamples++;
  }
  // stop sampling
  ADCSRA = 0x00;
  if (lNoSamples>0)  // if no samples, micros did run over
  {  
    // correct quadradic current sum for offset: Sum((i(t)+o)^2) = Sum(i(t)^2) + 2*o*Sum(i(t)) + o^2*NoSamples
    // sum should be zero as we have sampled 5 cycles at 50Hz (or 6 at 60Hz)
    float fOffset = (float)lCurrentSum/lNoSamples;
    lCurrentSumSQ -= 2*fOffset*lCurrentSum + fOffset*fOffset*lNoSamples;
    if (lCurrentSumSQ<0) {lCurrentSumSQ=0;} // avoid NaN due to round-off effects
    fCurrentRMS = sqrtf((float)lCurrentSumSQ/(float)lNoSamples) * gfACS712_Factor * gfLineVoltage / 1024;
    // correct offset for next round
    giADCOffset=(int)(giADCOffset+fOffset+0.5f);
  }
    return fCurrentRMS;
}
// END AC CURRENT SENSOR //  

void DrawCircle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
     myGLCD.drawCircle (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].radius);
}

void DrawRectangle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
     myGLCD.drawRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void DrawRoundRectangle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BordercolorR, pageElements[elementID].BordercolorG, pageElements[elementID].BordercolorB);
     myGLCD.drawRoundRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void FillCircle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
     myGLCD.fillCircle (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].radius);
}

void FillRectangle (int elementID) {
     myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
     myGLCD.fillRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void FillRoundRectangle (int elementID) {
    myGLCD.setColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
    myGLCD.fillRoundRect (pageElements[elementID].sX, pageElements[elementID].sY, pageElements[elementID].eX, pageElements[elementID].eY);
}

void DrawButton (int elementID) {
     FillRoundRectangle(elementID);
     DrawRoundRectangle(elementID);
     DrawTextBox(elementID);
}
void SetFont (int font){
      switch (font){
      case 1:
      myGLCD.setFont(SmallFont);
      break;
      case 2:
      myGLCD.setFont(BigFont);
      break;
      case 3:
      myGLCD.setFont(SevenSegNumFont);
      break;
     }  
}

void DrawTextBox (int elementID) {
     myGLCD.setColor(pageElements[elementID].colorR, pageElements[elementID].colorG, pageElements[elementID].colorB);
     myGLCD.setBackColor(pageElements[elementID].BGcolorR, pageElements[elementID].BGcolorG, pageElements[elementID].BGcolorB);
     SetFont(pageElements[elementID].font);
     myGLCD.print(pageElements[elementID].label, pageElements[elementID].sX+3, pageElements[elementID].sY+3);   
}

void DrawDone (int elementID) {
      pageElements[elementID].redraw = 0;
}

void DrawPage (int pageID) {
   for(int i=0; i<= 3; i = i +1){
   if (pageID == pageElements[i].pageID) {
     if (pageElements[i].redraw == 1){
      switch(pageElements[i].type){ //  1 = button, 2 = rectangle, 3 = round rectangle, 4 = text box, 5 = circle, 6 = filled rectangle, 7 = filled round rectangle, 8 = filled circle
       case 1:
       DrawButton(i);
       DrawDone(i);
       break;
       case 2:
       DrawRectangle(i);
       DrawDone(i);
       break;
       case 3:
       DrawRoundRectangle(i);
       DrawDone(i);
       break;
       case 4:
       DrawTextBox(i);
       DrawDone(i);
       break;
       case 5:
       DrawCircle(i);
       DrawDone(i);
       break;
       case 6:
       FillRectangle(i);
       DrawDone(i);
       break;
       case 7:
       FillRoundRectangle(i);
       DrawDone(i);
       break;
       case 8:
       FillCircle(i);
       DrawDone(i);
       break;
       }
     }
   }
  }
}

void setup() {
 Serial.begin(9600);
 pinMode(46, OUTPUT);
 pinMode(A0, INPUT);
 pinMode(A1, INPUT);
 pinMode(A2, INPUT);
 pinMode(A3, INPUT);
 
 dht.begin();
 myGLCD.InitLCD(LANDSCAPE);      //LANDSCAPE or PORTRAIT
 myGLCD.clrScr();
 myTouch.InitTouch(LANDSCAPE);
 myTouch.setPrecision(PREC_MEDIUM);
 SD.begin(53);
}

now it broke the other way arround ... it starts out fine and then after a while it ignores the millisecond If's and just refreshes every loop ...

//Update AC Sensor every 1 second
  if (ttac == 0) { ttac = millis(); }
  if ((millis() - ttac) >= 1000) {
  str= ACSensorPoll();
  str.toCharArray(pageElements[2].label,6);
  pageElements[2].redraw = 1;
  ttac = millis();
  
  }  
//END Update AC

how can this be true every loop all of a sudden? i dont understand ... both if statements with millis() start to be always TRUE after a few seconds ... or he stops doing

void DrawDone (int elementID) {
      pageElements[elementID].redraw = 0;
}

redraw is a bool, should i rather set them with TRUE and FALSE instead of 1 and 0?

i attached the current sketch ...

after a few seconds both IF statements in the void loop become always TRUE ... so either the arduino is broken or memory messes up? maybe i should just not use a struct but individual global variables instead?

sketch.ino (9.36 KB)

no one has any idea why this is happening? =)

int ttdht = 0;
int ttcls = 0;
int ttac = 0;

integers goes from -32768 to 32767.

millis() returns an unsigned long, and it goes from 0 to 4,294,967,295

Your variables will overflow in ~30 seconds. Is that how long it works as expected?

oh ... my ... god ... smacks forehead

that is probably exactly whats happening lol ... thank you so much im gonna go test it with correct data types!

yes, thank you so much for pointing this out ... everything now works as expected and i can continue with my original plan!