Thanks I think I am now having more success with the MCUFRIEND library
I am currently trying to make buttons that will allow selection of different menu screens (basically a main menu that will make it easier to select the correct function) I have been using the simple button example from the library as a template to build on but I am unsure as to how to make this select different screens and then allow the buttons on those new screens to function
//load required libraries
#include "Adafruit_GFX.h"
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include "TouchScreen.h"
#include <OneWire.h>
#include <DallasTemperature.h>
//set touchscreen input pins
#define MINPRESSURE 10
#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 = 75, TS_RT = 905, TS_TOP = 99, TS_BOT = 921;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button sensor, WC, WC_WC10, WC_WC20, WC_WC50, WC_Top, WC_Return; //list of buttons
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;
}
//Set up TFT colours
#define BLACK 0x0000
#define BLUE 0x001F
#define DARKBLUE 0x0010
#define VIOLET 0x8888
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GOLD 0xFEA0
#define BROWN 0xA145
#define SILVER 0xC618
#define LIME 0x07E0
//Set temperature probe input
#define ONE_WIRE_BUS 22
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//Set varibles to run menu codes
int currentpage = 0; //0=homescreen, 1=waterchange menu, 2=temperature sensors.....
void setup()//////////////////
{
// initialising touch screen display
tft.reset();
tft.begin(tft.readID());
Serial.begin(9600);
Serial.println();
Serial.print("reading id....0x");
delay(500);
Serial.println(tft.readID(), HEX);
tft.fillScreen(BLACK); //fill screen with colour
tft.setRotation(0); //horizontal orientation
tft.setTextSize(3); //set size of font
tft.setTextColor(WHITE); //set colour of text
Serial.println("Dallas Temperature IC Control Library Demo");
sensors.begin();
}
//Draw menu screen
void drawHome()
{
tft.fillScreen(BLACK);
tft.fillRect(40, 80, 160, 80, BLUE);// Menu header (start X, start Y, Length, Height
tft.setTextSize(2);
tft.setFont();
tft.setTextColor(WHITE);
tft.setCursor(70, 120);
tft.print(" QA Manager");
sensor.initButton(&tft, 60, 200, 100, 40, CYAN, CYAN, BLACK, "Temp", 2); // sensor menu
WC.initButton(&tft, 180, 200, 100, 40, CYAN, CYAN, BLACK, "Manage", 2); //waterchange menu
Adafruit_GFX_Button *buttons[] = {&sensor, &WC, NULL};
bool update_button(Adafruit_GFX_Button *b, bool down)
{
b->press(down && b->contains(pixel_x, pixel_y));
if (b->justReleased())
b->drawButton(false);
if (b->justPressed())
b->drawButton(true);
return down;
}
/* most screens have different sets of buttons
* life is easier if you process whole list in one go
*/
bool update_button_list(Adafruit_GFX_Button **pb)
{
bool down = Touch_getXY();
for (int i = 0 ; pb[i] != NULL; i++) {
update_button(pb[i], down);
}
return down;
}
}
void drawWC()
{
tft.fillScreen(BLACK);
tft.fillRect(25, 30, 190, 80, BLUE, WHITE, "Water Changes", 2);// Menu header (start X, start Y, Length, Height
tft.setTextSize(2);
tft.setFont();
tft.setTextColor(WHITE);
tft.setCursor(50, 55);
tft.print("Water Changes");
WC_WC10.initButton(&tft, 60, 140, 100, 40, CYAN, CYAN, BLACK, "WC 10%", 2);
WC_WC20.initButton(&tft, 60, 190, 100, 40, CYAN, CYAN, BLACK, "WC 20%", 2);
WC_WC50.initButton(&tft, 60, 240, 100, 40, CYAN, CYAN, BLACK, "WC 50%", 2);
WC_Top.initButton(&tft, 180, 140, 100, 40, CYAN, CYAN, BLACK, "Top Up", 2);
WC_Return.initButton(&tft, 180, 240, 100, 40, RED, Red, BLACK, "Back", 2);
Adafruit_GFX_Button *buttons[] = {&WC_WC10, &WC_WC20, &WC_WC50, &WC_Top, &WC_Return, NULL};
delay(300);
bool update_button(Adafruit_GFX_Button *b, bool down)
{
b->press(down && b->contains(pixel_x, pixel_y));
if (b->justReleased())
b->drawButton(false);
if (b->justPressed())
b->drawButton(true);
return down;
}
}
void loop(void)
}
if (WC.justPressed()) {
currentpage==1;
drawWC(); //open waterchange menu
}
}
}
}
Does anyone have any advice