Thanks David.
That's what I did initially, I just moved the stylus until it registered a touch and proceeded with the calibration. When I ran into trouble with the button sketch later on I assumed it had something to do with the calibration problems.
I modified your button_simple example to create 4 buttons on the display. Button 1 is near the corner with the problem but is quite large so it does work normally. The problem is that buttons 2, 3, and 4 only work about 80% of the time. The other 20% of the time they register a touch on button 1. I also get the same result when I try this with the button_list example. Here is the code:
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=125,TS_RT=922,TS_TOP=946,TS_BOT=92;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button btn1, btn2, btn3, btn4;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
return pressed;
}
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
void setup(void)
{
Serial.begin(9600);
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
Serial.println("Calibrate for your Touch Panel");
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(0); //PORTRAIT
tft.fillScreen(BLACK);
btn1.initButton(&tft, 80, 120, 140, 220, WHITE, WHITE, BLACK, "1", 2);
btn2.initButton(&tft, 80, 360, 140, 220, WHITE, WHITE, BLACK, "2", 2);
btn3.initButton(&tft, 240, 120, 140, 220, WHITE, WHITE, BLACK, "3", 2);
btn4.initButton(&tft, 240, 360, 140, 220, WHITE, WHITE, BLACK, "4", 2);
btn1.drawButton(false);
btn2.drawButton(false);
btn3.drawButton(false);
btn4.drawButton(false);
}
void loop(void)
{
bool down = Touch_getXY();
btn1.press(down && btn1.contains(pixel_x, pixel_y));
btn2.press(down && btn2.contains(pixel_x, pixel_y));
btn3.press(down && btn3.contains(pixel_x, pixel_y));
btn4.press(down && btn4.contains(pixel_x, pixel_y));
if (btn1.justReleased())
btn1.drawButton();
if (btn2.justReleased())
btn2.drawButton();
if (btn3.justReleased())
btn3.drawButton();
if (btn4.justReleased())
btn4.drawButton();
if (btn1.justPressed()) {
btn1.drawButton(true);
Serial.println("1");
}
if (btn2.justPressed()) {
btn2.drawButton(true);
Serial.println("2");
}
if (btn3.justPressed()) {
btn3.drawButton(true);
Serial.println("3");
}
if (btn4.justPressed()) {
btn4.drawButton(true);
Serial.println("4");
}
}