Adafruit TouchScreen
TouchScreen.h
1 // Touch screen library with X Y and Z (pressure) readings as well
2 // as oversampling to avoid 'bouncing'
3 // (c) ladyada / adafruit
4 // Code under MIT License
5 
6 #ifndef _ADAFRUIT_TOUCHSCREEN_H_
7 #define _ADAFRUIT_TOUCHSCREEN_H_
8 #include <stdint.h>
9 
10 #if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) || \
11  defined(TEENSYDUINO) || defined(__AVR_ATmega2560__) || \
12  defined(__AVR_ATmega4809__)) && \
13  !defined(__IMXRT1062__)
14 typedef volatile uint8_t RwReg;
15 #elif defined(ARDUINO_STM32_FEATHER)
16 typedef volatile uint32 RwReg;
17 #elif defined(NRF52_SERIES) || defined(ESP32) || defined(ESP8266) || \
18  defined(ARDUINO_ARCH_STM32) || defined(__IMXRT1062__)
19 typedef volatile uint32_t RwReg;
20 #else
21 typedef volatile uint32_t RwReg;
22 #endif
23 
24 #if defined(__AVR__) || defined(TEENSYDUINO) || defined(ARDUINO_ARCH_SAMD)
25 #define USE_FAST_PINIO
26 #endif
27 
30 class TSPoint {
31 public:
32  TSPoint(void);
33  TSPoint(int16_t x, int16_t y, int16_t z);
34 
35  bool operator==(TSPoint);
36  bool operator!=(TSPoint);
37 
38  int16_t x,
39  y,
40  z;
41 };
44 class TouchScreen {
45 public:
56  TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);
57 
63  bool isTouching(void);
64  uint16_t pressure(void);
65  int readTouchY();
66  int readTouchX();
67  TSPoint getPoint();
69 
70 private:
71  uint8_t _yp, _ym, _xm, _xp;
72  uint16_t _rxplate;
73 
74 #if defined(USE_FAST_PINIO)
75  volatile RwReg *xp_port, *yp_port, *xm_port, *ym_port;
76  RwReg xp_pin, xm_pin, yp_pin, ym_pin;
77 #endif
78 };
79 
80 #endif
bool operator==(TSPoint)
Check if the current point is equivalent to another point.
Definition: TouchScreen.cpp:44
Definition: TouchScreen.h:44
int16_t y
state variable for the y value
Definition: TouchScreen.h:38
Definition: TouchScreen.h:30
int16_t z
state variable for the z value
Definition: TouchScreen.h:38
int16_t pressureThreshhold
Pressure threshold for isTouching
Definition: TouchScreen.h:68
int16_t x
state variable for the x value
Definition: TouchScreen.h:38
bool operator!=(TSPoint)
Check if the current point is not equivalent to another point.
Definition: TouchScreen.cpp:55