diff --git a/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino b/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino index aebcc8c..de4a9c5 100644 --- a/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino +++ b/examples/TouchDrv_CST9217_GetPoint/TouchDrv_CST9217_GetPoint.ino @@ -30,7 +30,7 @@ #include #include #include -#include "TouchDrvCST92xx.h" +#include "touch/TouchDrvCST92xx.h" #include "SensorWireHelper.h" @@ -89,8 +89,8 @@ void setup() // Set to skip register check, used when the touch device address conflicts with other I2C device addresses [0x5A] - touch.jumpCheck(); - + // touch.jumpCheck(); + touch.setPins(SENSOR_RST, SENSOR_IRQ); bool result = touch.begin(Wire, touchAddress, SENSOR_SDA, SENSOR_SCL); diff --git a/examples/TouchDrv_CSTxxx_GetPoint/TouchDrv_CSTxxx_GetPoint.ino b/examples/TouchDrv_CSTxxx_GetPoint/TouchDrv_CSTxxx_GetPoint.ino index ee629c0..cb58fc6 100644 --- a/examples/TouchDrv_CSTxxx_GetPoint/TouchDrv_CSTxxx_GetPoint.ino +++ b/examples/TouchDrv_CSTxxx_GetPoint/TouchDrv_CSTxxx_GetPoint.ino @@ -50,6 +50,7 @@ TouchDrvCSTXXX touch; int16_t x[5], y[5]; +bool isPressed = false; void scanDevices(void) { @@ -119,13 +120,20 @@ void setup() } touch.setPins(SENSOR_RST, SENSOR_IRQ); - touch.begin(Wire, address, SENSOR_SDA, SENSOR_SCL); + // Support CST81X CST226 CST9217 CST9220 .... + bool result = touch.begin(Wire, address, SENSOR_SDA, SENSOR_SCL); + if (result == false) { + while (1) { + Serial.println("Failed to initialize CST series touch, please check the connection..."); + delay(1000); + } + } Serial.print("Model :"); Serial.println(touch.getModelName()); // T-Display-S3 CST816 touch panel, touch button coordinates are is 85 , 160 - touch.setCenterButtonCoordinate(85, 360); + // touch.setCenterButtonCoordinate(85, 360); // T-Display-AMOLED 1.91 Inch CST816T touch panel, touch button coordinates is 600, 120. // touch.setCenterButtonCoordinate(600, 120); // Only suitable for AMOLED 1.91 inch @@ -151,25 +159,33 @@ void setup() // Set mirror xy // touch.setMirrorXY(true, true); + //Register touch plane interrupt pin + attachInterrupt(SENSOR_IRQ, []() { + isPressed = true; + }, FALLING); + } void loop() { - uint8_t touched = touch.getPoint(x, y, touch.getSupportTouchPoint()); - if (touched) { - for (int i = 0; i < touched; ++i) { - Serial.print("X["); - Serial.print(i); - Serial.print("]:"); - Serial.print(x[i]); - Serial.print(" "); - Serial.print(" Y["); - Serial.print(i); - Serial.print("]:"); - Serial.print(y[i]); - Serial.print(" "); + if (isPressed) { + isPressed = false; + uint8_t touched = touch.getPoint(x, y, touch.getSupportTouchPoint()); + if (touched) { + for (int i = 0; i < touched; ++i) { + Serial.print("X["); + Serial.print(i); + Serial.print("]:"); + Serial.print(x[i]); + Serial.print(" "); + Serial.print(" Y["); + Serial.print(i); + Serial.print("]:"); + Serial.print(y[i]); + Serial.print(" "); + } + Serial.println(); } - Serial.println(); } delay(5);