Hi,
I have a small 2.4" TFT touch display shield from china connected to my Arduino Uno. I can read the touch screen and output to the TFT fine but I'm having some issues doing state change detection in order to be able to create a button. I've used the same idea as in the state change example from the Arduino IDE.
Here is my code
int state = 0;
int laststate = 0;
void loop() {
// put your main code here, to run repeatedly:
TSPoint p = ts.getPoint();
if(p.z>minPressure && p.z<maxPressure){
state = 1;
}
else{
state = 0;
}
if (laststate != state){
if (state ==1){
Serial.print("On");
}
else{
Serial.print("Off");
}
}
laststate = state;
}
I would expect it to print On in the serial monitor while I am touching the display and then off when I release it. Instead what is happening is it is printing on and then off in rapid succession to the serial monitor.
Display I am using
The library I am using for display
sketch_mar30a.ino (1.02 KB)