Something is wierd here... I can draw rect and fillrect all I want and it works great and follows what I expect in locating the start size all works well.
BUT! If I try to draw and position a button using touchscreen.h or touchscreen_kbv.h with mcufriend_kbv.
tft.drawButton() and tft.initButton(&tft, 64, 107, 117, 90, BLUE, GREEN, BLACK, "", 1) well that button is in my upper left corner at what I would line up as 5, 5 with drawRect...
I also noticed that if my button is more then 115, then my first position of that button moves as my button is getting larger!
In this example the M5 button is on my left side about 3/4 of the way down my screen, while my Select_btn is full width of my screen starting at same distance from the left side as M5 (which is about 5 pixel (note the value of 64!)) but for the large button to be position just under that same value is now 239! WTF!
m5_btn.initButton(&tft, 64, 200, 117, 90, BLUE, GREEN, BLACK, "", 1);
Select_btn.initButton(&tft, 239, 281, 472, 70, BLUE, GREEN, BLACK, "", 1);
Not very good at this, thry not to laugth too mutch ![]()
Richard
#define PORTRAIT 0
#define LANDSCAPE 1
#define TOUCH_ORIENTATION LANDSCAPE
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include "TouchScreen_kbv.h" //my hacked version
//---------------------------------------------------------------------------
// defining fonts to be used in app
#include <fonts/FreeSerif9pt7b.h>
#include <fonts/FreeSerif12pt7b.h>
#include <fonts/FreeSerif18pt7b.h>
#include <fonts/FreeSerif24pt7b.h>
#include <fonts/FreeSerifBold9pt7b.h>
#include <fonts/FreeSerifBold12pt7b.h>
#include <fonts/FreeSerifBold18pt7b.h>
#include <fonts/FreeSerifBold24pt7b.h>
//---------------------------------------------------------------------------
// defining colors
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//---------------------------------------------------------------------------
// Defining the touch screen parameters
int XP = 9, XM = A3, YP = A2, YM = 8; //240x320 ID=0x9338
const int TS_LEFT = 130, TS_RT = 905, TS_TOP = 930, TS_BOT = 75;
TouchScreen_kbv ts(XP, YP, XM, YM, 300); //re-initialised after diagnose
TSPoint_kbv tp; //global point
#define MINPRESSURE 250 // this is where we define the minimum pressure on the touch screen
#define MAXPRESSURE 1000 // this is where we define the maximum pressure on the touch screen
Adafruit_GFX_Button m1_btn, m2_btn, m3_btn, m4_btn, m5_btn, m6_btn, m7_btn, m8_btn, Select_btn, Setup_btn, Radio1_btn, Radio2_btn; //
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
TSPoint_kbv 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) {
switch (tft.getRotation()) {
case 0: //PORTRAIT
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width());
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
break;
case 1: //LANDSCAPE
pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
break;
}
}
return pressed;
}
void drawmybuttons() {
tft.setCursor(1, 1);
if (numberButtons == 8) {
m1_btn.initButton(&tft, 64, 107, 117, 90, BLUE, GREEN, BLACK, "", 1);
m1_btn.drawButton();
m2_btn.initButton(&tft, 183, 107, 117, 90, BLUE, GREEN, BLACK, "", 1);
m2_btn.drawButton();
m3_btn.initButton(&tft, 301, 107, 117, 90, BLUE, GREEN, BLACK, "", 1);
m3_btn.drawButton();
m4_btn.initButton(&tft, 419, 107, 117, 90, BLUE, GREEN, BLACK, "", 1);
m4_btn.drawButton();
} else {
m1_btn.initButton(&tft, 0, 0, 0, 0, BLACK, BLACK, BLACK, "", 0);
m2_btn.initButton(&tft, 0, 0, 0, 0, BLACK, BLACK, BLACK, "", 0);
m3_btn.initButton(&tft, 0, 0, 0, 0, BLACK, BLACK, BLACK, "", 0);
m4_btn.initButton(&tft, 0, 0, 0, 0, BLACK, BLACK, BLACK, "", 0);
}
m5_btn.initButton(&tft, 64, 200, 117, 90, BLUE, GREEN, BLACK, "", 1);
m5_btn.drawButton();
m6_btn.initButton(&tft, 183, 200, 117, 90, BLUE, GREEN, BLACK, "", 1);
m6_btn.drawButton();
m7_btn.initButton(&tft, 301, 200, 117, 90, BLUE, GREEN, BLACK, "", 1);
m7_btn.drawButton();
m8_btn.initButton(&tft, 419, 200, 117, 90, BLUE, GREEN, BLACK, "", 1);
m8_btn.drawButton();
Select_btn.initButton(&tft, 239, 281, 472, 70, BLUE, GREEN, BLACK, "", 1);
Select_btn.drawButton();
}