Try a short delay after you press the screen so you have time to remove your finger before the next reading.
Quick way using delay();
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read(); // this reads the touchscreen
int x1=myTouch.getX(); // assign the x and y coordinates to variables
int y1=myTouch.getY(); //
int i;
if ((y1>=31) && (y1<=49)) {
if ((x1>=142) && (x1<=160)) {
waitForIt(142, 30, 162, 54);
//This is where I'm not able to think of.......
//Increase the number
i++;
myGLCD.printNumI(i, 110, 33);
delay(500); // Half second delay
}
if ((y1>=31) && (y1<=49)) {
if ((x1>=162) && (x1<=179)) {
waitForIt(162, 31, 179, 49);
//This is where I'm not able to think of.......
//Decrease the number
i--;
myGLCD.printNumI(i, 110, 33);
delay(500); // Half second delay
}
}
}
}
}
Proper way using millis()
long now; // put these before setup with other variables
long end;
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read(); // this reads the touchscreen
int x1=myTouch.getX(); // assign the x and y coordinates to variables
int y1=myTouch.getY(); //
int i;
if ((y1>=31) && (y1<=49)) {
if ((x1>=142) && (x1<=160)) {
waitForIt(142, 30, 162, 54);
//This is where I'm not able to think of.......
//Increase the number
i++;
myGLCD.printNumI(i, 110, 33);
MyDelay(); // Calls proper delay
}
if ((y1>=31) && (y1<=49)) {
if ((x1>=162) && (x1<=179)) {
waitForIt(162, 31, 179, 49);
//This is where I'm not able to think of.......
//Decrease the number
i--;
myGLCD.printNumI(i, 110, 33);
MyDelay(); // Calls proper delay
}
}
}
}
}
void MyDelay()
{
long now = millis();
long end = now + 500; // Set delay for half a second
while(millis() < end)
{
// Do what you want during delay
}
}
Even better way cleaning up the code abit and giving more space between buttons for more accurate button reading.
Also erasing previously printed number.
int i; // put these before setup with other variables
long now;
long end;
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read(); // this reads the touchscreen
int x1=myTouch.getX(); // assign the x and y coordinates to variables
int y1=myTouch.getY(); //
if ((y1>=31) && (y1<=49)) {
if ((x1>=150) && (x1<=168)) {
waitForIt(150, 31, 168, 49);
//This is where I'm not able to think of.......
//Increase the number
i++;
MyDelay(); // Calls proper delay
}
if ((x1>=178) && (x1<=195)) {
waitForIt(178, 31, 195, 49);
//This is where I'm not able to think of.......
//Decrease the number
i--;
MyDelay(); // Calls proper delay
}
}
}
}
}
void MyDelay()
{
myGLCD.print(" ", 90, 33); // Erase previous number
long now = millis();
long end = now + 500; // Set delay for half a second
while(millis() < end)
{
myGLCD.printNumI(i, 90, 33); //print new number during delay
}
}