Here i am going to attached my GUI button for LED ON/OFF along with my code.
1.But i do not understand which calibrated value i have to insert in my calibration code?
2. How to get this calibration value as given below-
#define MINPRESSURE 200------- How to set this value in my code?
#define MAXPRESSURE 1000
#define TS_MINX 204
#define TS_MINY 195
#define TS_MAXX 948
#define TS_MAXY 910
Note- Also i am going to attached my GUI Picture as given below-
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
//#include <Fonts/FreeMonoOblique9pt7b.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
const int XP = 8, XM = A2, YP = A3, YM = 9; //ID=0x7789
const int TS_LEFT = 128, TS_RT = 916, TS_TOP = 921, TS_BOT = 88;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define myLED 53
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.y, TS_TOP, TS_BOT, 0, 320); //.kbv makes sense to me
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, 480);
}
return pressed;
}
void setup() {
Serial.begin(9600);
pinMode(myLED, OUTPUT);
tft.reset();
tft.begin(0x9486);
tft.setRotation(1); //0-Portrait 1-Landscape
page1();
delay(3000);
//page2();
}
void page1() {
tft.fillRect(30, 90, 190, 150, BLUE);
tft.drawRect(30, 90, 190, 150, WHITE);
tft.setCursor(50, 160);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("ON/OFF");
tft.setCursor(50, 200);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("LIGHTS");
----- How can i get this touch calibration as given below so that my LED ON/OFF gui button work Properly?-------
bool down = Touch_getXY();
while (!down) {
down = Touch_getXY();
if (pixel_x > 30 && pixel_x < 300 && pixel_y > 190 && pixel_y < 130) { //LED on
//digitalWrite(myLED, HIGH);
//down = false;
}
else if (pixel_x > 180 && pixel_x < 280 && pixel_y > 180 && pixel_y < 220) { //LED off
digitalWrite(myLED, LOW);
down = false;
}
else{
down = false;
}
