Code: Select all
if (p.z < MINPRESSURE || p.z >MAXPRESSURE) touched = LOW;
Code: Select all
boolean touchState;
boolean lastTouchState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
boolean touched;
void setup() {
}
void loop() {
touchscreen();
}
void touchscreen(){
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z < MINPRESSURE || p.z >MAXPRESSURE) touched = LOW;
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) touched = HIGH;
if (touched != lastTouchState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (touched != touchState) {
touchState = touched;
if (touchState == HIGH) {
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.width());
switch( tft.getRotation() ) {
case 3:
swap(p.x, p.y);
p.x = (480 - p.x);
break;
}
if (p.y < 183 && p.y > 55) {
if (p.x < 48) {
if(mute[0] == false) {
tft.fillRect(0, 40, 48, 12, WHITE);
tft.setCursor(4, 41);
tft.print("MUTED");
mute[0] = true;
}
else if(mute[0] == true) {
tft.fillRect(0, 40, 48, 12, COLOR1);
mute[0] = false;
}
}
else if (p.x < 96) { // some more areas follow, truncated them for posting...
if(mute[1] == false) {
tft.fillRect(48, 40, 48, 12, WHITE);
tft.setCursor(52, 41);
tft.print("MUTED");
mute[1] = true;
}
else if(mute[1] == true) {
tft.fillRect(48, 40, 48, 12, COLOR2);
mute[1] = false;
}
}
}
}
}
}
lastTouchState = touched;
}