groundFungus:
if(p.x > 305 && p.x < 319 && p.y > 387 && p.y < 470)
{
i=0;
flag1 == false;
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
break;
}
Is that the button test code? Does it not do what you want? What does it do?
I suggest that you post the whole program. [Snippets often omit important information.](https://snippets-r-us.com/) If the code is too large to post it can be attached. Better yet, make a [minimal verifiable program](https://stackoverflow.com/help/minimal-reproducible-example) that shows the problem.
Karma for code tags on the first post. Most new members fail to read the forum guidelines.
#include "Adafruit_GFX.h"
#include "MCUFRIEND_kbv.h"
#include "TouchScreen.h"
#include <stdint.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define TS_MINX 114
#define TS_MINY 122
#define TS_MAXX 940
#define TS_MAXY 915
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define BLACK 0x0000 /* 0, 0, 0 */
#define BLUE 0x001F /* 0, 0, 255 */
#define RED 0xF800 /* 255, 0, 0 */
#define GREEN 0x07E0 /* 0, 255, 0 */
#define CYAN 0x07FF /* 0, 255, 255 */
#define MAGENTA 0xF81F /* 255, 0, 255 */
#define YELLOW 0xFFE0 /* 255, 255, 0 */
#define WHITE 0xFFFF /* 255, 255, 255 */
#define NAVY 0x000F /* 0, 0, 128 */
#define DARKGREEN 0x03E0 /* 0, 128, 0 */
#define DARKCYAN 0x03EF /* 0, 128, 128 */
#define MAROON 0x7800 /* 128, 0, 0 */
#define PURPLE 0x780F /* 128, 0, 128 */
#define OLIVE 0x7BE0 /* 128, 128, 0 */
#define LIGHTGREY 0xC618 /* 192, 192, 192 */
#define DARKGREY 0x7BEF /* 128, 128, 128 */
#define ORANGE 0xFD20 /* 255, 165, 0 */
#define GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define PINK 0xF81F /* 255, 0, 255 */
int16_t i = 0;
boolean flag1;
MCUFRIEND_kbv tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
//******************************************************************************
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
// Restart the LCD
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(3); // Rotation of screen(0,1,2,3)
tft.fillScreen(WHITE); // color of BackGround
tft.fillRect(180, 80, 120, 40, NAVY);
tft.setCursor(210, 92);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Press");
// reset variables
flag1 = false;
i = 0;
}
//-----------------------------------
void loop()
{
while(flag1 == true)
{
tft.setCursor(130, 210);
tft.setTextColor(BLACK, WHITE);
tft.setTextSize(2);
tft.print(i);
if((i>10))
{
i=0;
flag1 = false;
}
TSPoint p = ts.getPoint();
if (p.z > ts.pressureThreshhold)
{
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 480);
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
}
if(p.x > 110 && p.x < 163 && p.y > 280 && p.y < 395)
{
i=0;
flag1 == false;
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
break;
}
}
i++;
delay(1000);
}
Thank You for the reply
I attach the full code. In fact it should show a counter at the bottom of the screen counting up to 50, and button at top that can stop the counter.
It just show the button, and I don't know why the counter part doesn't work.
The main ideal I need counter that can be stooped by screen touch button