Ok, here is a simplified version of the same code, everything but the screen functions and serial have been removed.
Without the while() statement it prints to the screen and I get serial responses. With the while() statement, I get only the setup functions (the lines being drawn), there are no loop functions(myGLCD.print).
The only other thing I can remove is the UTFT_Geometry library if you'd like.
broken:
#include <UTFT.h>
#include <UTFT_Geometry.h>
#include <UTouch.h>
// Initialize display
UTFT myGLCD(ITDB32S,38,39,40,41);
UTFT_Geometry geo(&myGLCD);
// Initialize touchscreen
UTouch myTouch( 6, 5, 4, 3, 2);
// Declare fonts
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
//Touch Screen X,Y
int x, y;
//************Custom Functions*******************//
void drawButtons()
{
//Up Button
myGLCD.setColor(112, 138, 144);
myGLCD.fillRoundRect (250, 10, 310, 110);
myGLCD.setColor(0, 0, 255);
myGLCD.drawRoundRect (250, 10, 310, 110);
myGLCD.setColor(255, 0, 0);
geo.drawTriangle(255,75,305,75,280,35);
geo.fillTriangle(255,75,305,75,280,35);
//Down Button
myGLCD.setColor(112, 138, 144);
myGLCD.fillRoundRect (250, 130, 310, 230);
myGLCD.setColor(0, 0, 255);
myGLCD.drawRoundRect (250, 130, 310, 230);
myGLCD.setColor(50, 50, 255);
geo.drawTriangle(255,165,305,165,280,205);
geo.fillTriangle(255,165,305,165,280,205);
}
// When called draws 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(0, 0, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void drawFrame()
{
myGLCD.setColor(0,0,255);
myGLCD.drawLine(0,0,0,147);
myGLCD.drawLine(0, 0, 200, 0);
myGLCD.drawLine(0, 27, 200, 27);
myGLCD.drawLine(0, 57, 200, 57);
myGLCD.drawLine(0, 87, 200, 87);
myGLCD.drawLine(0, 117, 200, 117);
myGLCD.drawLine(0, 147, 200, 147);
myGLCD.drawLine(120, 0, 120, 147);
myGLCD.drawLine(200, 0, 200, 147);
}
//****************End of Custom Functions*************//
void setup()
{
Serial.begin(9600);
//Touch Screen Initialization
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
//myGLCD.setBackColor(0, 0, 255);
drawButtons();
drawFrame();
}
void loop()
{
while(true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
Serial.print(F("Touch Screen X "));
Serial.println(x);
Serial.print(F("Touch Screen Y "));
Serial.println(y);
if ((x>=248) && (x<=315)) // Upper row
{
if ((y>=5) && (y<=105)) // Button: UP
{
waitForIt(250, 10, 310, 110);
}
if ((y>=135) && (y<=315)) // Button: DOWN
{
waitForIt(250, 130, 310, 230);
}
}
}
}
myGLCD.setColor(255,255,255);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Case Temp(C):"),10, 7);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Humidity (%):"),10, 37);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Res Temp (C):"),10, 67);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Dew Point(C):"),10, 97);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Set Point(C):"),10, 127);
}
working:
#include <UTFT.h>
#include <UTFT_Geometry.h>
#include <UTouch.h>
// Initialize display
UTFT myGLCD(ITDB32S,38,39,40,41);
UTFT_Geometry geo(&myGLCD);
// Initialize touchscreen
UTouch myTouch( 6, 5, 4, 3, 2);
// Declare fonts
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
//Touch Screen X,Y
int x, y;
//************Custom Functions*******************//
void drawButtons()
{
//Up Button
myGLCD.setColor(112, 138, 144);
myGLCD.fillRoundRect (250, 10, 310, 110);
myGLCD.setColor(0, 0, 255);
myGLCD.drawRoundRect (250, 10, 310, 110);
myGLCD.setColor(255, 0, 0);
geo.drawTriangle(255,75,305,75,280,35);
geo.fillTriangle(255,75,305,75,280,35);
//Down Button
myGLCD.setColor(112, 138, 144);
myGLCD.fillRoundRect (250, 130, 310, 230);
myGLCD.setColor(0, 0, 255);
myGLCD.drawRoundRect (250, 130, 310, 230);
myGLCD.setColor(50, 50, 255);
geo.drawTriangle(255,165,305,165,280,205);
geo.fillTriangle(255,165,305,165,280,205);
}
// When called draws 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(0, 0, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void drawFrame()
{
myGLCD.setColor(0,0,255);
myGLCD.drawLine(0,0,0,147);
myGLCD.drawLine(0, 0, 200, 0);
myGLCD.drawLine(0, 27, 200, 27);
myGLCD.drawLine(0, 57, 200, 57);
myGLCD.drawLine(0, 87, 200, 87);
myGLCD.drawLine(0, 117, 200, 117);
myGLCD.drawLine(0, 147, 200, 147);
myGLCD.drawLine(120, 0, 120, 147);
myGLCD.drawLine(200, 0, 200, 147);
}
//****************End of Custom Functions*************//
void setup()
{
Serial.begin(9600);
//Touch Screen Initialization
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
//myGLCD.setBackColor(0, 0, 255);
drawButtons();
drawFrame();
}
void loop()
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
Serial.print(F("Touch Screen X "));
Serial.println(x);
Serial.print(F("Touch Screen Y "));
Serial.println(y);
if ((x>=248) && (x<=315)) // Upper row
{
if ((y>=5) && (y<=105)) // Button: UP
{
waitForIt(250, 10, 310, 110);
}
if ((y>=135) && (y<=315)) // Button: DOWN
{
waitForIt(250, 130, 310, 230);
}
}
}
myGLCD.setColor(255,255,255);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Case Temp(C):"),10, 7);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Humidity (%):"),10, 37);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Res Temp (C):"),10, 67);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Dew Point(C):"),10, 97);
myGLCD.setFont(SmallFont);
myGLCD.print(F("Set Point(C):"),10, 127);
}