Counter/timer questions (solved)

Hi

I searched the net for simple counter for arduino mega and touchscreen display. Found some for LCD displays but did not understand them very well. So I came up with a simple code of my own. Counters/timers work but I I would like to add the function that if there is 5 minutes left, then the background for that timer would go red. I tried if time < 5 minutes, it kind of works but it flickers. Another problem is that after 10 minutes comes 9, so 9 gets printed in place of 1 and 0 stays there displaying 90 minutes. I tried drawing filled black rectangles but again results were flickery. Using if time is bigger than 0 and only then print text I achieved that it does not start counting minus minutes but for that there is also better solution. Any help is appreciated.

Its only my second arduino project so dont hit in the face if the code is terrible.

#include <UTFT.h>
#include <UTouch.h>
extern uint8_t BigFont[];


UTFT        myGLCD(ITDB32S, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch      myTouch(6,5,4,3,2);
int x, y;
long timer1;
long aeg1; 
long timer2;
long aeg2; 
long timer3;
long aeg3; 
long timer4;
long aeg4; 
long timer5;
long aeg5;
long timer6;
long aeg6; 
 

void setup()
{

   myGLCD.InitLCD();
   myGLCD.clrScr();
   myGLCD.setBackColor(VGA_BLACK);
   myGLCD.setColor(VGA_WHITE);
   myGLCD.setFont(BigFont);
   myGLCD.drawRoundRect(0,0,150,40);
   myGLCD.print("I LIIN",10,12);
   myGLCD.drawRoundRect(0,40,150,80);
   myGLCD.print("II LIIN",10,52);
   myGLCD.drawRoundRect(0,80,150,120);
   myGLCD.print("III LIIN",10,92);
   myGLCD.drawRoundRect(0,120,150,160);
   myGLCD.print("IV LIIN",10,132);
   myGLCD.drawRoundRect(0,160,150,200);
   myGLCD.print("CREMONA1",10,172);
   myGLCD.drawRoundRect(0,200,150,239);
   myGLCD.print("CREMONA2",10,212);
   myGLCD.drawRoundRect(170,0,319,40);
   myGLCD.drawRoundRect(170,40,319,80);
   myGLCD.drawRoundRect(170,80,319,120);
   myGLCD.drawRoundRect(170,120,319,160);
   myGLCD.drawRoundRect(170,160,319,200);
   myGLCD.drawRoundRect(170,200,319,239);
   myTouch.InitTouch();
   myTouch.setPrecision(PREC_HI);
}
void loop()
{
    aeg1=timer1-millis();
    if (0 <= aeg1){
    myGLCD.printNumI((aeg1/60000),229,12,1);
    }
    else{
    }
    
    aeg2=timer2-millis();
    if (0 <= aeg2){
    myGLCD.printNumI((aeg2/60000),229,52,1);
    }
    else{
    }
    
    aeg3=timer3-millis();
    if (0 <= aeg3){
    myGLCD.printNumI((aeg3/60000),229,92);
    }
    else{
    }
    
    aeg4=timer4-millis();
    if (0 <= aeg4){
    myGLCD.printNumI((aeg4/60000),229,132);
    }
    else{
    } 
    
    aeg5=timer5-millis();
    if (0 <= aeg5){
    myGLCD.printNumI((aeg5/60000),229,172);
    }
    else{
    }     
    
    aeg6=timer6-millis();
    if (0 <= aeg6){
    myGLCD.printNumI((aeg6/60000),229,212);
    }
    else{
    }   
      
    
    myGLCD.setColor(VGA_WHITE);
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      if ((x>=0) && (x<=150))
      if ((y>=0) && (y<=40)){
      timer1=millis()+3600000;
    }
      if ((x>=0) && (x<=150))
      if ((y>=40) && (y<=80)){
      timer2=millis()+3600000;
    }
      if ((x>=0) && (x<=150))
      if ((y>=80) && (y<=120)){
      timer3=millis()+2700000;
    }
      if ((x>=0) && (x<=150))
      if ((y>=120) && (y<=160)){
      timer4=millis()+1500000;
    }
          if ((x>=0) && (x<=150))
      if ((y>=160) && (y<=200)){
      timer5=millis()+1800000;
    }
      if ((x>=0) && (x<=150))
      if ((y>=200) && (y<=240)){
      timer6=millis()+1800000;
    }
    
  }
}

estmote:

  aeg1=timer1-millis();As you've not given timer1 a value it will be 0 by default. millis() is the number of milliseconds since the Arduino was powered up/reset. So you're taking an almost random number away from zero which will leave aeg1 as a negative number. Therefore,:   if (0 <= aeg1) will always be false. What, exactly, are you trying to do here?

Thank you for interest.

Pushing a button gives timer1 value:
timer1=millis()+3600000;
if (0 <= aeg1) then means that when i start the program all the timers are 0 and will not show -1 in a minute if buttons are not pressed.

How to make the program do something once then the timer reaches a certain value? Lets say that this action should happen when timer goes under 5 minutes.
I wrote something like this:
if (0 <= aeg1 <= 300000) then draw red rectangle behind the timer
But this means that the program will draw the red rectangle over and over again, would be better if it drew it only once.

estmote:
Thank you for interest.

Pushing a button gives timer1 value:
timer1=millis()+3600000;

That's not in the code you posted above. I'm not a mind reader.
I suggest you look at the 'blink without delay' example in the IDE and also 'Finite State Machine'.

Sorry, but I posted the whole code and it is in the code I posted, so I am not assuming that anybody is a mind reader.
Thanks for advice will look at these examples once more.

I got the code doing what I needed.