I am trying to use the subj example sketch with modifications and have run into a problem. I have a new red MCUFRIEND 3.5" TFT ID 0x9486 installed on a Mega2560 board.
I can get the simple button example sketch to compile and work but want to operate in the landscape mode with 4 buttons.
I can move two buttons around in landscape with edits to the up/down tft.initbutton functions.
I can even rename the up/down names to v_tft and t_tft throughout the example sketch.
When I do this the location of the touch sensitive area is no longer associated with the new button locations.
When I attempt to expand this two button sketch to 4 buttons the new sketch will not compile.
I have enclosed my "latest" attempt plus the compiler error listing.
Is there someplace I can find a complete description of the MCUFRIEND library functions ?
What is the purpose of the empty U3 pas group marked W25032 ?
Any help will be greatly appreciated.
#if 1
#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 = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button v_btn, t_btn;
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(115200);
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(1); //PORTRAIT=0 LANDSCAPE=1
tft.fillScreen(BLACK); // Need to think about what to do here battery testing screen already in place
v_btn.initButton(&tft, 60, 300, 40, 40, WHITE, CYAN, BLACK, "V", 2);
t_btn.initButton(&tft, 125, 300, 40, 40, WHITE, CYAN, BLACK, "T", 2);
s_btn.initButton(&tft, 185, 300, 40, 40, WHITE, CYAN, BLACK, "S", 2);
u_btn.initButton(&tft, 245, 300, 40, 40, WHITE, CYAN, BLACK, "U", 2);
v_btn.drawButton(false);
t_btn.drawButton(false);
s_btn.drawButton(false);
u_btn.drawButton(false);
//tft.fillRect(40, 80, 160, 80, RED);
}
/* two buttons are quite simple
*/
void loop(void)
{
bool down = Touch_getXY();
v_btn.press(down && v_btn.contains(pixel_x, pixel_y));
t_btn.press(down && t_btn.contains(pixel_x, pixel_y));
s_btn.press(down && s_btn.contains(pixel_x, pixel_y));
u_btn.press(down && u_btn.contains(pixel_x, pixel_y));
if (v_btn.justReleased())
v_btn.drawButton();
if (t_btn.justReleased())
t_btn.drawButton();
if (s_btn.justReleased())
s_btn.drawButton();
if (u_btn.justReleased())
u_btn.drawButton();
if (v_btn.justPressed()) {
v_btn.drawButton(true);
//tft.fillRect(40, 80, 160, 80, GREEN); want to pass letter to external battery reading code
}
if (t_btn.justPressed()) {
t_btn.drawButton(true);
//tft.fillRect(40, 80, 160, 80, RED);
}
if (s_btn.justPressed()) {
s_btn.drawButton(true);
//tft.fillRect(40, 80, 160, 80, RED);
}
if (u_btn.justPressed()) {
u_btn.drawButton(true);
//tft.fillRect(40, 80, 160, 80, RED);
}
}
#endif
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Two Button push Error Msg >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Arduino: 1.8.10 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino: In function 'void setup()':
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino:55:72: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
v_btn.initButton(&tft, 60, 300, 40, 40, WHITE, CYAN, BLACK, "V", 2);
^
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino:56:72: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
t_btn.initButton(&tft, 125, 300, 40, 40, WHITE, CYAN, BLACK, "T", 2);
^
button_simple_test20191128:57:5: error: 's_btn' was not declared in this scope
s_btn.initButton(&tft, 185, 300, 40, 40, WHITE, CYAN, BLACK, "S", 2);
^~~~~
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino:57:5: note: suggested alternative: 't_btn'
s_btn.initButton(&tft, 185, 300, 40, 40, WHITE, CYAN, BLACK, "S", 2);
^~~~~
t_btn
button_simple_test20191128:58:5: error: 'u_btn' was not declared in this scope
u_btn.initButton(&tft, 245, 300, 40, 40, WHITE, CYAN, BLACK, "U", 2);
^~~~~
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino:58:5: note: suggested alternative: 't_btn'
u_btn.initButton(&tft, 245, 300, 40, 40, WHITE, CYAN, BLACK, "U", 2);
^~~~~
t_btn
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino: In function 'void loop()':
button_simple_test20191128:73:5: error: 's_btn' was not declared in this scope
s_btn.press(down && s_btn.contains(pixel_x, pixel_y));
^~~~~
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino:73:5: note: suggested alternative: 't_btn'
s_btn.press(down && s_btn.contains(pixel_x, pixel_y));
^~~~~
t_btn
button_simple_test20191128:74:5: error: 'u_btn' was not declared in this scope
u_btn.press(down && u_btn.contains(pixel_x, pixel_y));
^~~~~
C:\Users\Alan\Documents\Segway\Segway Battery Monitor\button_simple_test20191128\button_simple_test20191128.ino:74:5: note: suggested alternative: 't_btn'
u_btn.press(down && u_btn.contains(pixel_x, pixel_y));
^~~~~
t_btn
Multiple libraries were found for "Adafruit_GFX.h"
Used: C:\Users\Alan\Documents\Segway\libraries\Adafruit_GFX_Library
Multiple libraries were found for "MCUFRIEND_kbv.h"
Used: C:\Users\Alan\Documents\Segway\libraries\MCUFRIEND_kbv
Multiple libraries were found for "TouchScreen.h"
Used: C:\Users\Alan\Documents\Segway\libraries\Adafruit_TouchScreen
Multiple libraries were found for "SPI.h"
Used: C:\Users\Alan\Documents\ARDUNIO
exit status 1
's_btn' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

