Righty-O. I gave up on the mcufriend/mega combo and have been playing with the 320QVT/Mega combo. I have it working nicely using the UTFT library.
However, it has developed an issue. After the touch screen has been working for sometime, if I upload a new or updated sketch the touch screen stops responding. The rest of the display is as should be. I can upload a sketch that previously worked and now it doesn't. Is this a known issue with touch screens???
Just in case it is the cause (as it stands this sketch creates a display (page2) that contains various buttons. Pressing any button determines the value of a string then displays a new page (page1). Basic so far);
#include <UTFT.h>
#include <URTouch.h>
// define constants for stage names
/*#define STAGE1 "Mooramb."
#define STAGE2 "Dev Hill"
#define STAGE3 "Big Nob"
#define STAGE4 "Smoking."
#define STAGE5 "Mansfie."
#define STAGE6 "Ned Kel."
#define STAGE7 "Mt Bull."
#define STAGE8 "Jamieson"
#define STAGE9 "Serenity"
#define STAGE10 "Transit"*/
// list of stage names - max of 7 characters long
String STAGE[] = {"Moorab.","Dev Hil", "Big Nob", "Smoking","Mansfie", "Ned Kel", "Mt Bull", "Jamieso", "Serenit", "Transit"};
// data logging filename
String strFilename = "";
// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ILI9341_16,38,39,40,41);
// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield : 6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due : 6, 5, 4, 3, 2
// Teensy 3.x TFT Test Board : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
URTouch myTouch( 6, 5, 4, 3, 2);
// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
extern uint8_t SevenSegNumFont[];
int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";
/*************************
** Custom functions **
*************************/
void drawPage1()
{
myGLCD.setColor(34, 160, 198);
myGLCD.setFont(SmallFont);
myGLCD.fillRoundRect (40, 40, 280, 200);
}
void drawPage2()
{
// Draw the left column of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(34, 160, 198);
myGLCD.setFont(SmallFont);
myGLCD.fillRoundRect (122, 62+(x*36), 159, 88+(x*36)); //draw successive rectangles moving 52 down per one
myGLCD.setColor(27, 27, 246);
myGLCD.drawRoundRect (122, 62+(x*36), 159, 88+(x*36));
myGLCD.setColor(255, 255, 255);
myGLCD.print("OK", 132, 69+(x*36)); // use font BigFont
}
// Draw the right column of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(34, 160, 198);
myGLCD.fillRoundRect (281, 62+(x*36), 318, 88+(x*36)); //draw successive rectangles moving 52 down per one
myGLCD.setColor(27, 27, 246);
myGLCD.drawRoundRect (281, 62+(x*36), 318, 88+(x*36));
myGLCD.setColor(255, 255, 255);
myGLCD.print("OK", 291, 69+(x*36)); // use font BigFont
}
// Add Heading
myGLCD.setColor(35, 246, 27);
myGLCD.setFont(BigFont);
myGLCD.print("SELECT STAGE", 60, 10); // use font BigFont
// Add left column stage names
for (x=0; x<5; x++)
{
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(BigFont);
myGLCD.print(STAGE[x], 5, 67+(x*36)); // use font BigFont
}
// Add right column stage names
for (x=0; x<5; x++)
{
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(BigFont);
myGLCD.print(STAGE[x+5], 164, 67+(x*36)); // use font BigFont
}
}
// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
/*************************
** Required functions **
*************************/
void setup()
{
// Initial setup
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 0);
drawPage2();
}
void loop()
{
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=62) && (y<=87)) // Row1
{
if ((x>=122) && (x<=158)) // Stage1
{
waitForIt(122, 62, 158, 87);
strFilename = STAGE[0];
drawPage1();
}
if ((x>=281) && (x<=317)) // Stage6
{
waitForIt(281, 62, 317, 87);
strFilename = STAGE[5];
drawPage1();
}
}
if ((y>=98) && (y<=123)) // Row2
{
if ((x>=122) && (x<=158)) // Stage2
{
waitForIt(122, 98, 158, 123);
strFilename = STAGE[1];
drawPage1();
}
if ((x>=281) && (x<=317)) // Stage7
{
waitForIt(281, 98, 317, 123);
strFilename = STAGE[6];
drawPage1();
}
}
if ((y>=134) && (y<=159)) // Row3
{
if ((x>=122) && (x<=158)) // Stage3
{
waitForIt(122, 134, 158, 159);
strFilename = STAGE[2];
drawPage1();
}
if ((x>=281) && (x<=317)) // Stage8
{
waitForIt(281, 134, 317, 159);
strFilename = STAGE[7];
drawPage1();
}
}
if ((y>=170) && (y<=195)) // Row4
{
if ((x>=122) && (x<=158)) // Stage4
{
waitForIt(122, 170, 158, 195);
strFilename = STAGE[3];
drawPage1();
}
if ((x>=281) && (x<=317)) // Stage9
{
waitForIt(281, 170, 317, 195);
strFilename = STAGE[8];
drawPage1();
}
}
if ((y>=206) && (y<=231)) // Row5
{
if ((x>=122) && (x<=158)) // Stage5
{
waitForIt(122, 206, 158, 231);
strFilename = STAGE[4];
drawPage1();
}
if ((x>=281) && (x<=317)) // Stage10
{
waitForIt(281, 206, 317, 231);
strFilename = STAGE[9];
drawPage1();
}
}
}
}
}
I am using the Arduino IDE 1.8.5 downloaded from the Windows store running on a Windows 10 lappy.
I don't want to go chasing shadows if these touch displays are normally this unstable...