I made good progress after lifting some code off a number pad demo and changing drivers to reflect the AdaLGDP4535TFTLCD.h lib. Then getting the pins to align with the Map, it works pretty good. One last bit of coaching requested.
When I write text to the screen, in this case select a number from the displayed pad, it displays in the middle as expected But how do I clear the previous value without refreshing the whole screen causing it to flash , or otherwise how can I just clear the value, and enter the new value. As it is, it just accumulates until the two digits are filled. Thanks
{
tft.setCursor(90,150); // setCursor(x0,y)
tft.setTextColor(BLUE); // setTextColor(color);
tft.setTextSize(3); // setTextSize(#);
tft.print(""); //Clear previous value? um no!
tft.print(actual);
Serial.println(actual);
}
Basic demo for LGDP4535 for anyone else needing a starter kit.
// mega with AdaLGDP4535TFTLCD.h // Hardware-specific library
//
// Lifted and modified from from http://forum.arduino.cc/index.php?topic=292777.0
//Modifed input pins Display in portait mode
//Display (Number Pad) 1-16
// X
//╔═══════╗
// 13,9 ,5,1
// 14,10,6,2
// 15,11,7,3 ║ USB(Mega)
// 16,12,8,4
//╚═══════╝ Y
//TFT
// X
//╔══════════════╗
//║ 240,0 240,320 ║
//║ ║
//║ ║ USB(Mega)
//║ 0,0 0,320 ║
//╚══════════════╝ Y
//
//#define DEBUG
#include <Adafruit_GFX.h> // Core graphics library
//#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <AdaLGDP4535TFTLCD.h> // Hardware-specific library
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
//Touch Cfg
#define YP A3 // must be an analog pin, use "An" notation! //swapped
#define XM A2 // must be an analog pin, use "An" notation! //swapped
#define YM 9 // can be a digital pin //swapped
#define XP 8 // can be a digital pin //swapped
#define TS_MINX 130 //140
#define TS_MINY 130 //140
#define TS_MAXX 960 //900
#define TS_MAXY 970 //950
//Touch
// X
//╔══════════════╗
//║ 960,130 960,970║
//║ ║
//║ ║ USB(Mega)
//║ 130,130 130,970║
//╚══════════════╝ Y
#define PENRADIUS 10 //increased from 3
#define MINPRESSURE 10
#define MAXPRESSURE 1000
int x,y;
static int anterior=0, actual;
static unsigned long int tanterior=0, tactual=0;
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
int matriz[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
void setup(void) {
Serial.begin(115200); //Changed Baud
Serial.println(F("TFT LCD test"));
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
Serial.println(identifier, HEX);
tft.begin(identifier);
DibuRects(WHITE);
DibuNums(RED);
//End Setup
}
void loop(void)
{
TSPoint p = ts.getPoint();
// if sharing pins, you'll need to fix the directions of the touchscreen pins
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
{
// scale from 0->1023 to tft.width
p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, 0,tft.width())); //swapped
p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, 0,tft.height())); //swapped
x=(4*p.x)/tft.width();
y=(4*p.y)/tft.height();
actual=matriz[y][x];
tactual=millis();
if (tactual-tanterior>1000)
{
tanterior=tactual;
anterior=0;
// DibuRects(WHITE); //clear display of text
// DibuNums(RED); //clear display of text
}
if (actual!=anterior )
{
//Serial.println(actual);
PrintTFT();
anterior=actual;
#ifdef DEBUG
tft.fillCircle(p.x, p.y, PENRADIUS, BLUE);
#endif
}
}
//End Loop
}
unsigned long DibuRects(uint16_t color)
{
int width, height, i, j;
tft.fillScreen(BLACK);
width= tft.width()/4;
height= tft.height()/4;
for(i=0; i<4; i++)
for(j=0; j<4; j++)
{
tft.drawRect(i*width, j*height, width, height, color);
}
}
unsigned long DibuNums(uint16_t color)
{
int width, height, i, j;
width= tft.width()/4;
height= tft.height()/4;
#if defined __AVR_ATmega2560__
tft.setRotation(4);
#endif
for(i=0; i<4; i++)
for(j=0; j<4; j++) {
if((i+j*4+1)<=9)tft.setCursor(i*width+width/3, j*height+height/3);
else tft.setCursor(i*width+width/10, j*height+height/3);
tft.setTextColor(color);
tft.setTextSize(4);
tft.println(matriz[j][i]);
}
}
void PrintTFT()
{
tft.setCursor(90,150); // setCursor(x0,y)
tft.setTextColor(BLUE); // setTextColor(color);
tft.setTextSize(3); // setTextSize(#);
tft.print("");
tft.print(actual);
Serial.println(actual);
}