Hi,
I need help about push button function on touch screen..
With this sketch if I am touching the screen and holding it, pin 13 is going high then low then high then low then high... Etc and will be low after i released the screen.
My goal is as long as the screen is touching and holding pin 13 should stay in high. Not high then low then high then low... Etc... The pin 13 should be low after i released the screen.
Here is the sketch:
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop()
{
readingTouch();
oneTime();
}
void readingTouch()
{
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
X = map(p.x, TS_MAXX, TS_MINX, tft.width(), 0);
Y = map(p.y, TS_MAXY, TS_MINY, tft.height(), 0);
Z = p.z;
}
void oneTime()
{
if((X > 50 && X < 130) && (Y > 130 && Y < 190) && (Z > MINPRESSURE && Z < MAXPRESSURE) && a ==0 )
{
tft.fillRoundRect(rect_1x_x, rect_1x_y, width_rect,height_rect,round_rect, RED);
tft.drawRoundRect(rect_1x_x, rect_1x_y, width_rect,height_rect,round_rect,BLUE);
tft.setCursor(curs_1x_x,curs_1x_y);
tft.setTextSize(txt_btn_sz);
tft.setTextColor(YELLOW);
tft.println("1X");
Serial.print("\tPressure = "); Serial.println(Z);
digitalWrite(13,HIGH);
a=1;
delay(150);
}
else if ((Z < MINPRESSURE || Z > MAXPRESSURE) && (a == 1))
{
tft.fillRoundRect(rect_1x_x, rect_1x_y, width_rect,height_rect,round_rect, RED);
tft.drawRoundRect(rect_1x_x, rect_1x_y, width_rect,height_rect,round_rect,YELLOW);
tft.setCursor(curs_1x_x,curs_1x_y);
tft.setTextSize(txt_btn_sz);
tft.setTextColor(WHITE);
tft.println("1X");
Serial.print("\tNoPressure = "); Serial.println(Z);
digitalWrite(13,LOW);
a=0;
delay(150);
}
}
The serial print when I am touching and holding the touch screen:
Pressure = 488
NoPressure = 0
Pressure = 215
NoPressure = 0
Pressure = 201
NoPressure = 0
Pressure = 196
NoPressure = 0
Pressure = 184
NoPressure = 0
Pressure = 175
NoPressure = 0
Pressure = 200
NoPressure = 0