PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
967B

  1. #include <XPT2046_Touchscreen.h>
  2. #include <SPI.h>
  3. #define CS_PIN 8
  4. // MOSI=11, MISO=12, SCK=13
  5. // The TIRQ interrupt signal must be used for this example.
  6. #define TIRQ_PIN 2
  7. XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling
  8. void setup() {
  9. Serial.begin(38400);
  10. ts.begin();
  11. ts.setRotation(1);
  12. while (!Serial && (millis() <= 1000));
  13. }
  14. void loop() {
  15. // tirqTouched() is much faster than touched(). For projects where other SPI chips
  16. // or other time sensitive tasks are added to loop(), using tirqTouched() can greatly
  17. // reduce the delay added to loop() when the screen has not been touched.
  18. if (ts.tirqTouched()) {
  19. if (ts.touched()) {
  20. TS_Point p = ts.getPoint();
  21. Serial.print("Pressure = ");
  22. Serial.print(p.z);
  23. Serial.print(", x = ");
  24. Serial.print(p.x);
  25. Serial.print(", y = ");
  26. Serial.print(p.y);
  27. delay(30);
  28. Serial.println();
  29. }
  30. }
  31. }