#include
LCDTouch TouchPPP;
int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";
void drawButtons()
{
// Draw the upper row of buttons
for (x=0; x<5; x++)
{
TouchPPP.setColor(0, 0, 255);
TouchPPP.fillRoundRect (10+(x*60), 10, 60+(x*60), 60);
TouchPPP.setColor(255, 255, 255);
TouchPPP.drawRoundRect (10+(x*60), 10, 60+(x*60), 60);
TouchPPP.printNumI(x+1, 27+(x*60), 27,0,0);
}
// Draw the center row of buttons
for (x=0; x<5; x++)
{
TouchPPP.setColor(0, 0, 255);
TouchPPP.fillRoundRect (10+(x*60), 70, 60+(x*60), 120);
TouchPPP.setColor(255, 255, 255);
TouchPPP.drawRoundRect (10+(x*60), 70, 60+(x*60), 120);
if (x<4)
TouchPPP.printNumI(x+6, 27+(x*60), 87,0,0);
}
TouchPPP.print("0", 267, 87,0);
// Draw the lower row of buttons
TouchPPP.setColor(0, 0, 255);
TouchPPP.fillRoundRect (10, 130, 150, 180);
TouchPPP.setColor(255, 255, 255);
TouchPPP.drawRoundRect (10, 130, 150, 180);
TouchPPP.print("Clear", 40, 147,0);
TouchPPP.setColor(0, 0, 255);
TouchPPP.fillRoundRect (160, 130, 300, 180);
TouchPPP.setColor(255, 255, 255);
TouchPPP.drawRoundRect (160, 130, 300, 180);
TouchPPP.print("Enter", 190, 147,0);
TouchPPP.setBackColor (0, 0, 0);
}
void updateStr(int val)
{
if (stCurrentLen<20)
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
TouchPPP.setColor(0, 255, 0);
TouchPPP.print(stCurrent, LEFT, 224,0);
}
else
{
TouchPPP.setColor(255, 0, 0);
TouchPPP.print("BUFFER FULL!", CENTER, 192,0);
delay(500);
TouchPPP.print(" ", CENTER, 192,0);
delay(500);
TouchPPP.print("BUFFER FULL!", CENTER, 192,0);
delay(500);
TouchPPP.print(" ", CENTER, 192,0);
TouchPPP.setColor(0, 255, 0);
}
}
// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
TouchPPP.setColor(255, 0, 0);
TouchPPP.drawRoundRect (x1, y1, x2, y2);
while (TouchPPP.Touch_DataAvailable())
TouchPPP.Touch_Read();
TouchPPP.setColor(255, 255, 255);
TouchPPP.drawRoundRect (x1, y1, x2, y2);
}
void setup()
{
TouchPPP.LCDUTFT(LCD2_8);
TouchPPP.Touch_Init();
TouchPPP.Lcd_Init();
TouchPPP.clrScr();
TouchPPP.fillScr(0x0000);
TouchPPP.setPrecision(PREC_MEDIUM);
TouchPPP.setFont(16,16,32);
TouchPPP.setBackColor(0, 0, 255);
drawButtons();
}
void loop()
{
while (true)
{
if (TouchPPP.Touch_DataAvailable())
{
TouchPPP.Touch_Read();
x=320-(TouchPPP.Touch_GetX());
y=240-(TouchPPP.Touch_GetY());
if ((y>=10) && (y<=60)) // Upper row
{
if ((x>=10) && (x<=60)) // Button: 1
{
waitForIt(10, 10, 60, 60);
updateStr('1');
}
if ((x>=70) && (x<=120)) // Button: 2
{
waitForIt(70, 10, 120, 60);
updateStr('2');
}
if ((x>=130) && (x<=180)) // Button: 3
{
waitForIt(130, 10, 180, 60);
updateStr('3');
}
if ((x>=190) && (x<=240)) // Button: 4
{
waitForIt(190, 10, 240, 60);
updateStr('4');
}
if ((x>=250) && (x<=300)) // Button: 5
{
waitForIt(250, 10, 300, 60);
updateStr('5');
}
}
if ((y>=70) && (y<=120)) // Center row
{
if ((x>=10) && (x<=60)) // Button: 6
{
waitForIt(10, 70, 60, 120);
updateStr('6');
}
if ((x>=70) && (x<=120)) // Button: 7
{
waitForIt(70, 70, 120, 120);
updateStr('7');
}
if ((x>=130) && (x<=180)) // Button: 8
{
waitForIt(130, 70, 180, 120);
updateStr('8');
}
if ((x>=190) && (x<=240)) // Button: 9
{
waitForIt(190, 70, 240, 120);
updateStr('9');
}
if ((x>=250) && (x<=300)) // Button: 0
{
waitForIt(250, 70, 300, 120);
updateStr('0');
}
}
if ((y>=130) && (y<=180)) // Upper row
{
if ((x>=10) && (x<=150)) // Button: Clear
{
waitForIt(10, 130, 150, 180);
stCurrent[0]='\0';
stCurrentLen=0;
TouchPPP.setColor(0, 0, 0);
TouchPPP.fillRect(0, 224, 319, 239);
}
if ((x>=160) && (x<=300)) // Button: Enter
{
waitForIt(160, 130, 300, 180);
if (stCurrentLen>0)
{
for (x=0; x
{
stLast[x]=stCurrent[x];
}
stCurrent[0]='\0';
stCurrentLen=0;
TouchPPP.setColor(0, 0, 0);
TouchPPP.fillRect(0, 208, 319, 239);
TouchPPP.setColor(0, 255, 0);
TouchPPP.print(stLast, LEFT, 208,0);
}
else
{
TouchPPP.setColor(255, 0, 0);
TouchPPP.print("BUFFER EMPTY", CENTER, 192,0);
delay(500);
TouchPPP.print(" ", CENTER, 192,0);
delay(500);
TouchPPP.print("BUFFER EMPTY", CENTER, 192,0);
delay(500);
TouchPPP.print(" ", CENTER, 192,0);
TouchPPP.setColor(0, 255, 0);
}
}
}
}
}
} |