Hi, I'm using the 3.95" touchscreen tft for MEGA2560 with the ILI9488 microchip in it and I'm coming into a little bit of a conundrum when it comes to programming it. I just managed to figure out using the sample codes how to make a button and get it to touch, what I want to do is make a little touch screen keypad for my project so a number can be input much like a calculator.
I've created a number 1 button, and a number 2 button. The number 1 button works fine and multiplies by 10 and adds 1 to the count value. However whenever I touch the number 2 button, it seems to perform the number 1 button function first then the number 2 function. As in it multiplies by 10 adds 1 then multiplies by 10 and adds 2. I'm wondering if this is due to how my loop is written.
void loop(void)
{
px = 0;
py = 0;
my_touch.TP_Scan(0);
if (my_touch.TP_Get_State()&TP_PRES_DOWN)
{
px = my_touch.x;
py = my_touch.y;
}
if(is_pressed(70,110,220,260,px,py))
{
count = count * 10;
count = count + 1;
show_number( count, 150, 180, 3, YELLOW, BLACK, 0, 0);
delay(100);
}
if(is_pressed(140,150,220,260,px,py))
{
count = count * 10;
count = count + 2;
show_number( count, 150, 180, 3, YELLOW, BLACK, 0, 0);
delay(100);
}
}
The is_pressed command is formatted in the way of x min x max y min y max for the touch. I'm not that good at programming so I wouldn't know how to figure this out. When I swap the order of the two it seems to print a 2 then a 1 as if it is skipping the other if statement.