Thanks for the help aarg, I thought it would be something simple with the code but when I get stuck with no direction to go I post a topic and someone usually ask's me the right question and gets me moving in the right direction.
I was able to change the the basic code I posted along with a couple other things to get everything working properly. I changed the following code,
if (!tft.bufferEmpty()) {
TS_Point p = tft.getPoint();
to this,
if (tft.touched()) {
tft.touchRead(&tx,&ty);
along with changing a while statement to an if statement a little farther down.
I will post the completed code just in case someone has a similar problem in the future.
#include <SPI.h>
#include <Wire.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"
#define RA8875_CS 10
#define RA8875_RESET 9
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty;
byte rotation = 0;
int x, y;
const byte row = 4;
const byte col = 3;
byte lastHit = 0;
byte currentHit = 0;
Adafruit_GFX_Button btn[row * col];
const int TS_MAXX = 900, TS_MINX = 60, TS_MAXY = 920, TS_MINY = 80;
void setup() {
Serial.begin(9600);
if (!tft.begin(RA8875_800x480)) {
Serial.println("RA8875 Not Found!");
while (1);
}
Serial.println("Found RA8875");
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
tft.fillScreen(RA8875_BLACK);
tft.textMode();
tft.textSetCursor(20, 15);
tft.textEnlarge(2);
tft.textColor(RA8875_WHITE, RA8875_RED);
tft.textWrite("Choose how many petals you need.");
tft.graphicsMode();
tft.touchEnable(true);
btnGrid();
}
void loop() {
if (tft.touched()) {
tft.touchRead(&tx,&ty);
switch (rotation) {
case 0:
tx = map(tx, TS_MINX, TS_MAXX, 0, tft.width());
ty = map(ty, TS_MINY, TS_MAXY, 0, tft.height());
break;
case 1:
// p.x, p.y reversed //
tx = map(ty, TS_MINY, TS_MAXY, 0, tft.width());
ty = map(tx, TS_MAXX, TS_MINX, 0, tft.height());
break;
case 2:
tx = map(tx, TS_MAXX, TS_MINX, 0, tft.width());
ty = map(ty, TS_MAXY, TS_MINY, 0, tft.height());
break;
case 3:
// p.x, p.y reversed //
tx = map(ty, TS_MAXY, TS_MINY, 0, tft.width());
ty = map(tx, TS_MINX, TS_MAXX, 0, tft.height());
break;
}
}
if (tft.touched()) {
for (uint8_t b = 0; b < row * col; b++) {
if (btn[b].contains(tx, ty)) {
btn[b].press(true);
btn[b].drawButton(true);
currentHit = b;
} else if (btn[b].contains(tx, ty) == false) {
btn[b].press(false);
if (b == lastHit) {
btn[b].drawButton(false);
}
} else {
return;
}
}
lastHit = currentHit;
}
}
void btnGrid() {
int left, top;
int l = 50;
int t = 90;
int w = 200;
int h = 60;
byte hgap = 40;
byte vgap = 40;
byte id = 0;
char *titleStr[row * col] = {"4", "6", "8", "9", "12", "16", "Load", "1"};
for (byte j = 0; j < row; j++) {
for (byte i = 0; i < col; i++) {
left = l + i * (w + vgap);
top = t + j * (h + hgap);
btn[id].initButtonUL( &tft, left, top, w, h, RA8875_WHITE, RA8875_RED, RA8875_GREEN, titleStr[id], 3 );
if (id == currentHit) {
// inverted
btn[id].drawButton(true);
} else {
btn[id].drawButton(false);
}
id++;
}
}
}