Advertisement
MattRichardson

Touch Screen Arduino Sketch

Oct 15th, 2011
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  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.  
  5. #include <stdint.h>
  6. #include "TouchScreen.h"
  7.  
  8. #define YP A2  // must be an analog pin, use "An" notation!
  9. #define XM A3  // must be an analog pin, use "An" notation!
  10. #define YM 8   // can be a digital pin
  11. #define XP 9   // can be a digital pin
  12.  
  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.  
  18. void setup(void) {
  19.   Serial.begin(115200);
  20. }
  21.  
  22. void loop(void) {
  23.   // a point object holds x y and z coordinates
  24.   Point p = ts.getPoint();
  25.  
  26.   // we have some minimum pressure we consider 'valid'
  27.   // pressure of 0 means no pressing!
  28.   if (p.z > ts.pressureThreshhold) {
  29.      Serial.print("X"); Serial.print(p.x);
  30.      Serial.print("Y"); Serial.print(p.y);
  31.      Serial.print("P"); Serial.println(p.z);
  32.   }
  33.  
  34.   delay(0);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement