This menu wasn't working right. So I added 4 lines of code to show me what I was getting for touch data and it seems to be stupid all over the place. Two very different places on the screen will read at being touched at the same place. You can tell from this code that things would be much easier if my touch coordinates would line up with my display coordinates. How to I make that happen. I have run the calibration sketch several times. What next? My code (or actually someone elses I am trying to make work) is this...
And also, after adding the 4 lines of code there (its commented) I get garbled junk at the top of my screen. This is all something simple I am sure. Any insight would be apprecated.
// UTFT, Utouch
// (C)2013 Henning Karlsen
// web: Electronics - Henning Karlsen
// librerías
#include <UTFT.h>
#include <UTouch.h>
// Specific hardware
UTFT myGLCD(CTE50,38,39,40,41); // start up an instance of the TFT screen
UTouch myTouch(6,5,4,3,2);
//fonts
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
extern uint8_t swiss721_outline[];
extern uint8_t Sinclair_S[];
extern uint8_t TinyFont[];
// Color set
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define BLUE 0x001F
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define ORANGE 0xFD20
#define GREENa 0xAFE5
#define DARKGREEN 0x03E0
#define WHITE 0xFFFF
//touch reads
int x; int y;
//Design bars
int x11=750; int y11=0; int x12=795; int y12=495;
//Buttons
int x21=100; int y21=25; int x22=200; int y22=75; // Menu 1
int x31=100; int y31=125; int x32=200; int y32=175; // Menu 2
int x41=100; int y41=225; int x42=200; int y42=275; // Menu 3
int x51=250; int y51=206; int x52=350; int y52=y51+19; // Return to Main Menu
void MainMenu()
{
myGLCD.clrScr();
myGLCD.setColor(BLUE); myGLCD.fillRoundRect(x11,y11,x12,y12);
myGLCD.setBackColor(VGA_TRANSPARENT); myGLCD.setFont(swiss721_outline); myGLCD.setColor(WHITE); myGLCD.print("MAIN MENU",45,20);
myGLCD.setFont(SmallFont);
myGLCD.setColor(BLUE); button(x21,y21,x22,y22);
myGLCD.setBackColor(BLUE); myGLCD.setColor(WHITE); myGLCD.print("MENU 1",x21+4,y21+4);
myGLCD.setColor(GREEN); button(x31,y31,x32,y32);
myGLCD.setBackColor(GREEN); myGLCD.setColor(BLACK); myGLCD.print("MENU 2",x31+4,y31+4);
myGLCD.setColor(RED); button(x41,y41,x42,y42);
myGLCD.setBackColor(RED); myGLCD.setColor(WHITE); myGLCD.print("MENU 3",x41+4,y41+4);
while (true)
{
// Space for variable reads: Temperature values, sound spectrum analizer reads, hour, date, etc.
//Touch instructios
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
myGLCD.print("X",150,200); // These 4 Lines I added to tell me what I was getting as a touch reading.
myGLCD.print("Y",150,225); // After these 4 Lines added I get so garbled trash at the top of my screen. Why?
myGLCD.printNumI((int)x,200,200); // Why do my touch coordinates in no way line up to my display coords?
myGLCD.printNumI((int)y,200,225); // What Am I missing?
// Menu 1
if ((y>=y21) && (y<=y22))
{
if ((x>=x21) && (x<=x22))
{
Redbox(x21,y21,x22,y22);
Menu1();
}
}
//End Menu 1
// Menu 2
if ((y>=y31) && (y<=y32))
{
if ((x>=x31) && (x<=x32))
{
Redbox(x31,y31,x32,y32);
Menu2();
}
}
//End Menu 2
// Menu 3
if ((y>=y41) && (y<=y42))
{
if ((x>=x41) && (x<=x42))
{
Redbox(x41,y41,x42,y42);
Menu3();
}
}
//End Menu 3
}
}
}
void Menu1()
{
myGLCD.clrScr();
myGLCD.setColor(BLUE); myGLCD.fillRoundRect(x11,y11,x12,y12);
myGLCD.setBackColor(VGA_TRANSPARENT); myGLCD.setFont(swiss721_outline); myGLCD.setColor(WHITE); myGLCD.print("MENU 1",45,20);
myGLCD.setFont(SmallFont);
myGLCD.setColor(GREEN); button(x31,y31,x32,y32);
myGLCD.setBackColor(GREEN); myGLCD.setColor(BLACK); myGLCD.print("MENU 2",x31+4,y31+4);
myGLCD.setColor(RED); button(x41,y41,x42,y42);
myGLCD.setBackColor(RED); myGLCD.setColor(WHITE); myGLCD.print("MENU 3",x41+4,y41+4);
myGLCD.setColor(BLUE); button(x51,y51,x52,y52);
myGLCD.setBackColor(BLUE); myGLCD.setColor(WHITE); myGLCD.print("Main",x51+17,y51+4);
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
// Menu 2
if ((y>=y31) && (y<=y32))
{
if ((x>=x31) && (x<=x32))
{
Redbox(x31,y31,x32,y32);
Menu2();
}
}
//End Menu 2
// Menu 3
if ((y>=y41) && (y<=y42))
{
if ((x>=x41) && (x<=x42))
{
Redbox(x41,y41,x42,y42);
Menu3();
}
}
//End Menu 3
if ((y>=y51) && (y<=y52))
{
if ((x>=x51) && (x<=x52))
{
Redbox(x51,y51,x52,y52);
MainMenu();
}
}
}
}
}
void Menu2()
{
myGLCD.clrScr();
myGLCD.setColor(GREEN); myGLCD.fillRoundRect(x11,y11,x12,y12);
myGLCD.setBackColor(VGA_TRANSPARENT); myGLCD.setFont(swiss721_outline); myGLCD.setColor(WHITE); myGLCD.print("MENU 2",45,20);
myGLCD.setFont(SmallFont);
myGLCD.setColor(BLUE); button(x21,y21,x22,y22);
myGLCD.setBackColor(BLUE); myGLCD.setColor(WHITE); myGLCD.print("MENU 1",x21+4,y21+4);
myGLCD.setColor(RED); button(x41,y41,x42,y42);
myGLCD.setBackColor(RED); myGLCD.setColor(WHITE); myGLCD.print("MENU 3",x41+4,y41+4);
myGLCD.setColor(BLUE); button(x51,y51,x52,y52);
myGLCD.setBackColor(BLUE); myGLCD.setColor(WHITE); myGLCD.print("Main",x51+17,y51+4);
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
// Menu 1
if ((y>=y21) && (y<=y22))
{
if ((x>=x21) && (x<=x22))
{
Redbox(x21,y21,x22,y22);
Menu1();
}
}
//End Menu 1