My name is Chris, I just received the touchshield V2 and am playing with it, it is very cool!
I have one question about the touch part, in my code I put the following code:
// See if there's any touch data for us
if (ts.bufferEmpty()) {
return;
Like in the paint example, if I am slow at clicking it will draw lots of points (or give lots of touches registered instead of 1). I would like to put an anti-rebound part to avoid having 2 touches registered in the same 100ms for example.
I tried to find the code to do this in the library but cannot find what I am looking for. Is there a way to clear the buffer after reading the first value of x and y or to do a add an anti-rebound to avoid this?
I tried the other function:
// You can also wait for a touch
if (! ts.touched()) {
return;
}
by putting p.x = 0; and p.y = 0; after doing what I wanted I thought it would work but no, the touch screen keeps sending the last value that was touched.
I was then thinking of putting a condition on when to get the new values (like if they are the same as before, do not use them), but I would still have this rebound issue..
Thank you!
Best regards,
Chris
PS: code below.
Code: Select all
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h>
#include <Wire.h> // this is needed even tho we aren't using it
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
// This is the definition of the different positions for the logo
#define LOGOX 120
#define LOGOY 120
#define LOGORADIUS 80
// The STMPE610 uses hardware SPI on the shield, and #8
#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int oldcolor;
int currentcolor = ILI9341_BLUE;
int increment = 0;
void setup(void) {
// while (!Serial); // used for leonardo debugging
Serial.begin(9600);
Serial.println(F("Test!"));
if (!ts.begin()) {
Serial.println("Couldn't start touchscreen controller");
while (1);
}
Serial.println("Touchscreen started");
tft.begin();
tft.fillScreen(ILI9341_WHITE);
// make the logo in blue
tft.fillCircle(LOGOX, LOGOY, LOGORADIUS, currentcolor);
// Write text1 in blue
tft.setCursor(30, 220);
tft.setTextColor(currentcolor);
tft.setTextSize(5);
tft.println("text1");
// Write text2 in black
tft.setCursor(36, 260);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(1);
tft.println("text2");
//delay(2000);
}
void loop() {
// See if there's any touch data for us
//if (ts.bufferEmpty()) {
// return;
//}
// You can also wait for a touch
if (! ts.touched()) {
return;
}
// Retrieve a point
TS_Point p = ts.getPoint();
// Scale from ~0->4000 to tft.width using the calibration #'s
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
if ((p.y < (LOGOY + LOGORADIUS)) && (p.y > (LOGOY - LOGORADIUS))) {
if ((p.x < (LOGOX + LOGORADIUS)) && (p.x > (LOGOX - LOGORADIUS))) {
//oldcolor = currentcolor;
Serial.print("p.x: ");
Serial.println(p.x);
Serial.print("p.y: ");
Serial.println(p.y);
p.x = 0;
p.y = 0;
Serial.print("p.x: ");
Serial.println(p.x);
Serial.print("p.y: ");
Serial.println(p.y);
if (increment == 0){
currentcolor = ILI9341_BLUE;
}
if (increment == 1){
currentcolor = ILI9341_RED;
}
if (increment == 2){
currentcolor = ILI9341_GREEN;
}
if (increment == 3){
currentcolor = ILI9341_YELLOW;
}
/*
switch (increment) {
case 1:
currentcolor = ILI9341_RED;
break;
case 2:
currentcolor = ILI9341_GREEN;
break;
case 3:
currentcolor = ILI9341_YELLOW;
break;
default:
currentcolor = ILI9341_BLUE;
break;
}
*/
Serial.print("increment: ");
Serial.println(increment);
tft.fillCircle(LOGOX, LOGOY, LOGORADIUS, currentcolor);
tft.setCursor(30, 220);
tft.setTextColor(currentcolor);
tft.setTextSize(5);
tft.println("text1");
tft.setCursor(36, 260);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(1);
tft.println("text2");
increment++;
if (increment == 4){
increment = 0;
}
delay(1000);
}
}
}