Skip to content

Commit

Permalink
Updated example to limit touch detection interval #143
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Dec 16, 2024
1 parent cbec116 commit 020e3af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion examples/demo/demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool touchOnline = false;
uint32_t interval = 0;
int vref = 1100;
char buf[128];
uint32_t touch_loop_interval = 0;

struct _point {
uint8_t buttonID;
Expand Down Expand Up @@ -292,9 +293,12 @@ void setup()

epd_poweroff();


// Set the button callback function
btn.setPressedHandler(buttonPressed);

// Set the initial touch interval value
touch_loop_interval = millis() + 300;

}


Expand Down Expand Up @@ -356,6 +360,12 @@ void loop()


if (touchOnline) {

// Limit the touch detection interval and detect the touch status every 300ms
// https://github.com/Xinyuan-LilyGO/LilyGo-EPD47/issues/143
if (millis() < touch_loop_interval) {
return;
}
int16_t x, y;

if (!digitalRead(TOUCH_INT)) {
Expand Down Expand Up @@ -445,6 +455,7 @@ void loop()
*/
epd_poweroff_all();
}
touch_loop_interval = millis() + 300;
}

btn.loop();
Expand Down
13 changes: 12 additions & 1 deletion examples/touch/touch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* PSRAM:"OPI PSRAM"
* Upload Mode:"UART0/Hardware CDC"
* USB Mode:"Hardware CDC and JTAG"
*
*
*/

#ifndef BOARD_HAS_PSRAM
Expand Down Expand Up @@ -73,6 +73,7 @@ Rect_t area1 = {
.height = EPD_HEIGHT / 2 + 80
};
uint8_t state = 1;
uint32_t touch_loop_interval = 0;

void setup()
{
Expand Down Expand Up @@ -162,13 +163,23 @@ void setup()

epd_poweroff();


// Set the initial touch interval value
touch_loop_interval = millis() + 300;
}


int16_t x, y;

void loop()
{

// Limit the touch detection interval and detect the touch status every 300ms
// https://github.com/Xinyuan-LilyGO/LilyGo-EPD47/issues/143
if (millis() < touch_loop_interval) {
return;
}

uint8_t touched = touch.getPoint(&x, &y);
if (touched) {
// Serial.printf("X:%d Y:%d\n", x, y);
Expand Down

0 comments on commit 020e3af

Please sign in to comment.