PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

38 líneas
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. // These are the pins for the shield!
  7. #define YP A1 // must be an analog pin, use "An" notation!
  8. #define XM A2 // must be an analog pin, use "An" notation!
  9. #define YM 7 // can be a digital pin
  10. #define XP 6 // can be a digital pin
  11. #define MINPRESSURE 10
  12. #define MAXPRESSURE 1000
  13. // For better pressure precision, we need to know the resistance
  14. // between X+ and X- Use any multimeter to read it
  15. // For the one we're using, its 300 ohms across the X plate
  16. TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  17. void setup(void) {
  18. Serial.begin(9600);
  19. }
  20. void loop(void) {
  21. // a point object holds x y and z coordinates
  22. TSPoint p = ts.getPoint();
  23. // we have some minimum pressure we consider 'valid'
  24. // pressure of 0 means no pressing!
  25. if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
  26. Serial.print("X = "); Serial.print(p.x);
  27. Serial.print("\tY = "); Serial.print(p.y);
  28. Serial.print("\tPressure = "); Serial.println(p.z);
  29. }
  30. }