-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRead-Touch-Interrupt.ino
More file actions
109 lines (90 loc) · 3.19 KB
/
Read-Touch-Interrupt.ino
File metadata and controls
109 lines (90 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//============================================================================================//
/*
Filename: Read-Touch-Interrupt.ino
Description: Example Arduino sketch from the CSE_CST328 Arduino library.
Reads the touch sensor through interrupt method and prints the data to the serial monitor.
This code was written for and tested with FireBeetle-ESP32E board.
Framework: Arduino, PlatformIO
Author: Vishnu Mohanan (@vishnumaiea, @vizmohanan)
Maintainer: CIRCUITSTATE Electronics (@circuitstate)
Version: 0.1
License: MIT
Source: https://github.com/CIRCUITSTATE/CSE_CST328
Last Modified: +05:30 00:12:04 AM 27-03-2025, Thursday
*/
//============================================================================================//
#include <Wire.h>
#include <CSE_CST328.h>
#define CST328_PIN_RST 4
#define CST328_PIN_INT 16
#define CST328_PIN_SDA 21
#define CST328_PIN_SCL 22
//============================================================================================//
// Create a new instance of the CST328 class.
// Parameters: Width, Height, &Wire, Reset pin, Interrupt pin
CSE_CST328 tsPanel = CSE_CST328 (240, 320, &Wire, CST328_PIN_RST, CST328_PIN_INT);
bool intReceived = false; // Flag to indicate that an interrupt has been received
//============================================================================================//
/**
* @brief Setup runs once.
*
*/
void setup() {
Serial.begin (115200);
delay (100);
Serial.println();
Serial.println ("CST328 Touch Controller Test");
// Initialize the I2C interface (for ESP32).
Wire.begin (CST328_PIN_SDA, CST328_PIN_SCL);
// Initialize the touch panel.
tsPanel.begin();
// Attach the interrupt function.
attachInterrupt (digitalPinToInterrupt (CST328_PIN_INT), touchISR, FALLING);
delay (100);
}
//============================================================================================//
/**
* @brief Inifinite loop.
*
*/
void loop() {
if (intReceived) {
readTouch();
intReceived = false;
attachInterrupt (digitalPinToInterrupt (CST328_PIN_INT), touchISR, FALLING);
}
}
//============================================================================================//
/**
* @brief Reads a single touch point from the panel and print their info to the serial monitor.
*
*/
void readTouch() {
uint8_t point = 0;
if (tsPanel.isTouched (point)) {
Serial.print ("Touch ID: ");
Serial.print (point);
Serial.print (", X: ");
Serial.print (tsPanel.getPoint (point).x);
Serial.print (", Y: ");
Serial.print (tsPanel.getPoint (point).y);
Serial.print (", Z: ");
Serial.print (tsPanel.getPoint (point).z);
Serial.print (", State: ");
Serial.println (tsPanel.getPoint (point).state);
}
else {
Serial.println ("No touches detected");
}
}
//============================================================================================//
/**
* @brief The touch interrupt service routine.
*
*/
void touchISR() {
// Detach the interrupt to prevent multiple interrupts
detachInterrupt (digitalPinToInterrupt (CST328_PIN_INT));
intReceived = true;
}
//============================================================================================//