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.

36 lines
1.1KB

  1. // Touch screen library with X Y and Z (pressure) readings as well
  2. // as oversampling to avoid 'bouncing'
  3. // This demo code returns raw readings, public domain
  4. #include <stdint.h>
  5. #include "TouchScreen.h"
  6. #define YP A2 // must be an analog pin, use "An" notation!
  7. #define XM A3 // must be an analog pin, use "An" notation!
  8. #define YM 8 // can be a digital pin
  9. #define XP 9 // can be a digital pin
  10. // For better pressure precision, we need to know the resistance
  11. // between X+ and X- Use any multimeter to read it
  12. // For the one we're using, its 300 ohms across the X plate
  13. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  14. void setup(void) {
  15. Serial.begin(9600);
  16. }
  17. void loop(void) {
  18. // a point object holds x y and z coordinates
  19. TSPoint p = ts.getPoint();
  20. // we have some minimum pressure we consider 'valid'
  21. // pressure of 0 means no pressing!
  22. if (p.z > ts.pressureThreshhold) {
  23. Serial.print("X = "); Serial.print(p.x);
  24. Serial.print("\tY = "); Serial.print(p.y);
  25. Serial.print("\tPressure = "); Serial.println(p.z);
  26. }
  27. delay(100);
  28. }