Hi,
I've tried over and over to calibrate the ST7796S with TFTeSPI library. I don't know the calibration was easier with TFT_Touch by Rowboteer.
I tried this code:
Touch_calibrate.ino
With the same result.
And this is my touch.h settings:
// Initialise with example calibration values so processor does not crash if setTouch() not called in setup()
// x0 298, x1 3609, y0 194, y1 3586
// old calibration x0 120, x1 3580, y0 280, y1 3900
uint16_t touchCalibration_x0 = 298, touchCalibration_x1 = 3609, touchCalibration_y0 = 194, touchCalibration_y1 = 3586;
uint8_t touchCalibration_rotate = 0, touchCalibration_invert_x = 0, touchCalibration_invert_y = 1;
This is my simple button test:
#include <SPI.h>
#include <TFT_eSPI.h>
#define Z_THRSH 175
TFT_eSPI tft = TFT_eSPI();
struct button{
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
uint16_t color;
};
button b1, b2, b3;
void setup(void) {
Serial.begin(9600);
Serial.println("\n\nStarting...");
tft.init();
tft.setRotation(0);
tft.fillScreen(TFT_GREEN);
initialize_button(b1, 30, 30, 50, 50, TFT_BLACK);
initialize_button(b2, 30, 100, 50, 50, TFT_BLACK);
initialize_button(b3, 30, 170, 50, 50, TFT_BLACK);
draw_button(b1);
draw_button(b2);
draw_button(b3);
}
void loop() {
read_button(b1);
read_button(b2);
read_button(b3);
}
These are the button functions:
unsigned long buttonTimer = millis();
void initialize_button(button &b, uint16_t button_x, uint16_t button_y, uint8_t button_w, uint8_t button_h, uint16_t button_color){
b.x = button_x;
b.y = button_y;
b.w = button_w;
b.h = button_h;
b.color = button_color;
}
void draw_button(button &b){
tft.fillRect(b.x, b.y, b.w, b.h, TFT_YELLOW);//b.color
}
void read_button(button &b){
static bool toggle_button = 0;
uint16_t x, y;
uint16_t x_coordination, y_coordination;
if(millis() - buttonTimer > 10){
if(tft.getTouch(&x, &y, 350)){
buttonTimer = millis();
x_coordination = x;
y_coordination = y;
Serial.println("///////////////////////// read_button start");
Serial.print("X = "); Serial.println(x_coordination);
Serial.print("Y = "); Serial.println(y_coordination);
Serial.println("========================= read_button end");
Serial.println();
if(x_coordination >= b.x && x_coordination <= b.x + b.w && y_coordination >= b.y && y_coordination <= b.y + b.h){
if(!toggle_button){
tft.fillRect(b.x, b.y, b.w, b.h, TFT_RED);//b.color
toggle_button = 1;
}
else{
tft.fillRect(b.x, b.y, b.w, b.h, TFT_BLUE);//b.color
toggle_button = 0;
}
}
}
}
}