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;
}
}
}