Recently i purchased the 2.4" 320x240 Touchscreen For All Feathers (Product ID:3315), and loaded the example-sketch from arduino (touchpaint_feather). It works on the screen, the colors paint where i put my finger, but i was curious how the boxes work, but they did not work at all.
Now what i've tried, is to find out why it does not work correctly and for this i used a arduino sketch to print out original values, and mapped values:
Code: Select all
oid loop() {
// Retrieve a point
TS_Point p = ts.getPoint();
// Store unmapped
int16_t raw_x = p.x;
int16_t raw_y =p.y;
// 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());
Serial.print("Touchpoints are: [unm. / map.] x-axis:[");
Serial.print(raw_x);
Serial.print("/");
Serial.print(p.x);
Serial.print("] y-axis:[");
Serial.print(raw_y);
Serial.print("/");
Serial.print(p.y);
Serial.println("]");
delay(2500);
//copied from original adafruit example
if (p.y < BOXSIZE) {
oldcolor = currentcolor;
if (p.x < BOXSIZE) {
currentcolor = ILI9341_RED;
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
Serial.println("Box Used RED\n");
} else if (p.x < BOXSIZE*2) {
currentcolor = ILI9341_YELLOW;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
Serial.println("Box Used YELLOW\n");
} else if (p.x < BOXSIZE*3) {
currentcolor = ILI9341_GREEN;
tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
Serial.println("Box Used GREEN\n");
} else if (p.x < BOXSIZE*4) {
currentcolor = ILI9341_CYAN;
tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
Serial.println("Box Used CYAN\n");
} else if (p.x < BOXSIZE*5) {
currentcolor = ILI9341_BLUE;
tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
Serial.println("Box Used BLUE \n");
} else if (p.x < BOXSIZE*6) {
currentcolor = ILI9341_MAGENTA;
tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
Serial.println("Box Used MAGENTA\n");
}
}
When i touch somewhere middle of the screen i get:Touchpoints are: [unm. / map.] x-axis:[16379/-815] y-axis:[-260/-40]
Box Used RED
And when i press and hold on the pink/magenta box i get:Touchpoints are: [unm. / map.] x-axis:[1800/130] y-axis:[2054/167]
Touchpoints are: [unm. / map.] x-axis:[1777/131] y-axis:[2053/167]
Touchpoints are: [unm. / map.] x-axis:[1808/129] y-axis:[2051/167]
Touchpoints are: [unm. / map.] x-axis:[1817/129] y-axis:[1998/162]]
but obviously, after relasing the finger, the touchscreen is returning to relaxed state, and says that the red box is used.Touchpoints are: [unm. / map.] x-axis:[392/221] y-axis:[337/12]
Box Used MAGENTA
To check if the TFT Format is correct, i've printed out the tft parameters "tft.width()" and "tft.height()" and they are correctly 320x240px
Now i wonder how i can fix this issue? Any tips on this?
Also, think its rather inconvenient to have negative cordinates from the map function.