Hello all, I need some help with learning to program the TFT touch screen. I have a SSD1289 screen with a shield for the Mega 2560. The UTFT and Utouch libraries have been installed and the example sketch works ok. I have also run the calibration sketch and updated the configuration file.
My program is below, which is a very basic one. First page has a blue button which when pressed will then display the power page. On the power page there is a title and home text. The home text if operated will take me back to the first page.
I have two problems. The first is when I go to the power Page the text is still highlighted blue. Even though I have cleared the screen. How can I stop the text being highlighted.
The other problem is the touch can be out by a long way on some uploads. Where the button is top left I sometimes have to touch center of screen to change pages. If I upload the sketch a few times this on some occasions it all works ok. I am running on USB so is this a power issue or known problem with these screens.
Any help would be great thanks
#include <UTFT.h>
#include <UTouch.h>
UTFT myGLCD(SSD1289,38,39,40,41);
UTouch myTouch( 6, 5, 4, 3, 2);
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
int x, y;
char currentPage;
void setup(){
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setBackColor(0, 0, 255);
drawHomePage();
currentPage = '0';
}
void loop(){
if (currentPage == '0'){
if (myTouch.dataAvailable()){
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=10) && (y<=60) && (x>=10) && (x<=60)) { //button pressed
myGLCD.clrScr();
powerPageDraw();
currentPage = '1';
}
}
}
// POWER PAGE
if (currentPage == '1'){
if(myTouch.dataAvailable()){
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((x>=10) && (x<=60) && (y>=10) && (y<=20)) {
currentPage = '0';
drawHomePage();
}
}
}
}
void powerPageDraw(){
myGLCD.clrScr ();
myGLCD.setColor(255, 255, 255); //set color to white
myGLCD.setFont(SmallFont);
myGLCD.print("Home",10, 10);
myGLCD.print("Power Supplies",60, 10);
}
void drawHomePage(){
myGLCD.clrScr ();
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10, 10, 60, 60);
}