SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
gt9895_get_point.ino
Go to the documentation of this file.
1
30#include <TouchDrv.hpp>
31
32#ifndef TOUCH_SDA
33#define TOUCH_SDA 2
34#endif
35
36#ifndef TOUCH_SCL
37#define TOUCH_SCL 3
38#endif
39
40#ifndef TOUCH_IRQ
41#define TOUCH_IRQ 1
42#endif
43
44#ifndef TOUCH_RST
45#define TOUCH_RST 10
46#endif
47
49
50void setup()
51{
52 Serial.begin(115200);
53
54 while (!Serial);
55
56 delay(3000);
57
58 // Set touch interrupt and reset Pin
60
61 if (!touch.begin(Wire, GT9895_SLAVE_ADDRESS_L, TOUCH_SDA, TOUCH_SCL )) {
62 while (1) {
63 Serial.println("Failed to find GT9895 - check your wiring!");
64 delay(1000);
65 }
66 }
67
68 Serial.print("Chip ID : 0x"); Serial.println(touch.getChipID(), HEX);
69
70 // Sleep touch
71 // touch.sleep();
72
73 // int i = 10;
74 // while (i--) {
75 // Serial.print("Wake up after ");
76 // Serial.print(i);
77 // Serial.println(" seconds");
78 // delay(1000);
79 // }
80
81 // Wakeup touch
82 // touch.wakeup();
83
84 // Set touch max xy
85 // touch.setMaxCoordinates(240, 296);
86
87 // Set swap xy
88 // touch.setSwapXY(true);
89
90 // Set mirror xy
91 // touch.setMirrorXY(true, true);
92
93}
94
95void loop()
96{
97 /*
98 * Methods to increase the refresh rate:
99 * 1. Set the touch interrupt to a low level when touching, rather than a falling edge.
100 * Some are falling edge triggered, with a trigger period of about 10ms, depending on the firmware
101 * This requires the touch screen manufacturer to provide a firmware update, which is currently unavailable.
102 * 2. Use polling registers instead of interrupts, but this will consume CPU
103 */
104 TouchPoints touch_points = touch.getTouchPoints();
105 if (touch_points.hasPoints()) {
106 for (int i = 0; i < touch_points.getPointCount(); ++i) {
107 const TouchPoint &point = touch_points.getPoint(i);
108 Serial.print("X[");
109 Serial.print(i);
110 Serial.print("]:");
111 Serial.print(point.x);
112 Serial.print(" ");
113 Serial.print(" Y[");
114 Serial.print(i);
115 Serial.print("]:");
116 Serial.print(point.y);
117 Serial.print(" ");
118 }
119 Serial.println();
120 }
121}
@license MIT License
const TouchPoints & getTouchPoints() override
Get the touch points.
virtual bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr)
Initialize the touch driver with custom communication callbacks.
virtual void setPins(int rst, int irq)
Set the hardware reset and interrupt pin numbers.
virtual uint32_t getChipID()
Get the chip identifier (e.g., ID register value).
Container for touch point data and optional gesture information.
uint8_t getPointCount() const
Returns the number of stored touch points.
TouchPoint & getPoint(uint8_t index)
Gets a reference to a touch point at the specified index.
bool hasPoints() const
Checks whether any touch points are stored.
#define TOUCH_SDA
#define TOUCH_RST
void setup()
#define TOUCH_SCL
TouchDrvGT9895 touch
#define TOUCH_IRQ
void loop()
uint8_t i
Represents a single touch point with its properties.
uint16_t x
X coordinate of the touch point.
uint16_t y
Y coordinate of the touch point.