Hi,
Recently I bought the 2.8" TFT Touch Shield for Arduino - http://www.adafruit.com/products/376-. I like it and it works fine.
Now I am trying to create a menu and print the buttons in the screen, but unfortunately, the TFT doesn't print what I push.
In the example I atach the code, I am trying to print a "7". I've checked with the Serial.print that I get correctly the number...but for some reason the TFT can't print on the screen.
I attach the code:
void loop()
{
Point p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { // Si apreto un boto
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); // Recalculo les posicions X i Y
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
if (p.y >H1 && p.y<H5 ) {
if (p.x>X1 && p.x<X6){
if (p.x>X1 && p.x<X2){
if (p.y>H1 && p.y<H2){
tft.print(7);
}
}
----
Do you have any idea to solve it?
Thanks in advance,
A.
do not print in the screen
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: do not print in the screen
If you want to print the digit "7", use:
The quotes tell it that you want the literal character "7", not the ASCII character code 7 or BEL (In the old days, that was the character to send to the teletype machine to ring the bell )
Code: Select all
tft.print("7");
- tlerdrden
- Posts: 80
- Joined: Fri Nov 30, 2012 4:46 pm
Re: do not print in the screen
Yes, I was checked that before, sorry.
I have tried using:
tft.print(7);
tft-.print("7");
tft.println("7");
But anything happens, I don't know why. If I try to print it in other place of the code, it works with no problems, but the problem is that I want only that the number 7 appears when I push the key I've drawn in the screen.
I guess that I have to put the "tft.print" command in other place of the code, but where? Any idea to sync printings and touches to screen?
Thanks,
A.
I have tried using:
tft.print(7);
tft-.print("7");
tft.println("7");
But anything happens, I don't know why. If I try to print it in other place of the code, it works with no problems, but the problem is that I want only that the number 7 appears when I push the key I've drawn in the screen.
I guess that I have to put the "tft.print" command in other place of the code, but where? Any idea to sync printings and touches to screen?
Thanks,
A.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: do not print in the screen
I don't see where you are positioning the text cursor. Try setting the cursor position before you print.
- tlerdrden
- Posts: 80
- Joined: Fri Nov 30, 2012 4:46 pm
Re: do not print in the screen
I am sorry
I attach the code:
I attach the code:
Code: Select all
void loop()
{
Point p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { // Si apreto un boto
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); // Recalculo les posicions X i Y
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
if (p.y >H1 && p.y<H5 ) {
if (p.x>X1 && p.x<X6){
if (p.x>X1 && p.x<X2){
if (p.y>H1 && p.y<H2){
Serial.println(p.x); // Only to check I push the button
Serial.println(p.y); //Only to check I push the button
Serial.println(7); //Only to check that I am getting the button
tft.setCursor(30, 70); <-- SetCursor
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("7"); <-- Nothing happens!
} //END (p.y>Y1 && p.y<Y2
}//END (p.x>X1 && p.x<X2)
} // END (p.x>X1 && p.x<X6)
} // END (p.y >H1 && p.y<H5
} // END (p.z > MINPRESSURE && p.z < MAXPRESSURE)
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: do not print in the screen
Can you please post the entire sketch, so that we can try to reproduce the problem? Please use the 'Code' tags (tab at the top of the edit window) when posting code.
- tlerdrden
- Posts: 80
- Joined: Fri Nov 30, 2012 4:46 pm
Re: do not print in the screen
Yes of course:
Here is:
Here is:
Code: Select all
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#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
#define MINPRESSURE 10
#define MAXPRESSURE 1000
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Nuevos colores
#define GREY 50712
#define ORANGE 64800
#define PINK 63733
#define BROWN 35362
//BASIC PER FER UN MAP
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
//BASIC PER FER UN MAP
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin
//MIDAS RECUADRO BOTONES
#define X1 20 //
#define X2 60 //
#define X3 100 //
#define X4 140 //
#define X5 180 //
#define X6 220 //
#define DESCARX 15 // El desplazamiento en X respecto a las lineas horizontales de cada caracter
#define H1 150 //
#define H2 190 //
#define H3 230 //
#define H4 270 //
#define H5 310 //
#define DESCARY 10 // El desplazamiento en X respecto a las lineas horizontales de cada caracter
//Intentaré crear una calculadora amb les caixes de les pintures
#define TAMBOTON 40
// Creamos objetos "tft" y ts
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, 0);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
void setup(void) {
//Inicialización
Serial.begin(9600);
Serial.println("Paint!");
tft.reset();
uint16_t identifier = tft.readRegister(0x0);
if (identifier == 0x9325) {
Serial.println("Found ILI9325");
} else if (identifier == 0x9328) {
Serial.println("Found ILI9328");
} else if (identifier == 0x7575) {
Serial.println("Found HX8347G");
} else {
Serial.print("Unknown driver chip ");
Serial.println(identifier, HEX);
while (1);
}
//Inicialización
tft.begin(identifier);
tft.fillScreen(BLACK);
//Fico el titol
tft.setTextColor(RED);
tft.setTextSize(2);
tft.setCursor(30, 10);
tft.println("Opiron");
//Dibujo rectangulo de Operaciones
tft.drawRect(X1, 30, 200, 110, WHITE);
// Creo el cuadro donde habrá botones
tft.fillRect(X1, H1, X6-X1, H5-H1, GREY);
//Divido en lineas verticales el recuadro
tft.drawFastVLine(X2, H1, H4-H1, BLACK);
tft.drawFastVLine(X3, H1, H5-H1, BLACK);
tft.drawFastVLine(X4 , H1, H5-H1, BLACK);
tft.drawFastVLine(X5, H1, H5-H1, BLACK);
//Divido en lineas horizontales el recuadro
tft.drawFastHLine(X1, H2, X6-X1, BLACK);
tft.drawFastHLine(X1, H3, X6-X1, BLACK);
tft.drawFastHLine(X1, H4, X5-X1, BLACK);
//Ponemos numeros
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.setCursor(X1+DESCARX, H1+DESCARY);
tft.println("7");
tft.setCursor(X2+DESCARX, H1+DESCARY);
tft.println("8");
tft.setCursor(X3+DESCARX, H1+DESCARY);
tft.println("9");
tft.setCursor(X4+DESCARX, H1+DESCARY);
tft.println("/");
tft.setCursor(X5+DESCARX, H1+DESCARY);
tft.println("M");
tft.setCursor(X1+DESCARX, H2+DESCARY);
tft.println("4");
tft.setCursor(X2+DESCARX, H2+DESCARY);
tft.println("5");
tft.setCursor(X3+DESCARX, H2+DESCARY);
tft.println("6");
tft.setCursor(X4+DESCARX, H2+DESCARY);
tft.println("*");
tft.setCursor(X5+DESCARX, H2+DESCARY);
tft.println("C");
tft.setCursor(X1+DESCARX, H3+DESCARY);
tft.println("1");
tft.setCursor(X2+DESCARX, H3+DESCARY);
tft.println("2");
tft.setCursor(X3+DESCARX, H3+DESCARY);
tft.println("3");
tft.setCursor(X4+DESCARX, H3+DESCARY);
tft.println("-");
tft.setCursor(X2-5,H4+DESCARY);
tft.println("0");
tft.setCursor(X3+DESCARX, H4+DESCARY);
tft.println(".");
tft.setCursor(X4+DESCARX, H4+DESCARY);
tft.println("+");
tft.setCursor(X5+DESCARX, H4-5);
tft.println("=");
pinMode(13, OUTPUT);
}
void loop()
{
Point p = ts.getPoint();
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { // Si apreto un boto
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); // Recalculo les posicions X i Y
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
if (p.y >H1 && p.y<H5 ) {
if (p.x>X1 && p.x<X6){
if (p.x>X1 && p.x<X2){
if (p.y>H1 && p.y<H2){
Serial.println(p.x);
Serial.println(p.y);
Serial.println(7);
tft.setCursor(30, 70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("7");
} //FI (p.y>Y1 && p.y<Y2
}//FI (p.x>X1 && p.x<X2)
} // FI (p.x>X1 && p.x<X6)
} // FI (p.y >H1 && p.y<H5
} // FI evaluar boto (p.z > MINPRESSURE && p.z < MAXPRESSURE)
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: do not print in the screen
You must have an old version of the library. Where did you get it?
Your code gives me the following compilation error :
There is no 'readRegister' function in our library.
Anyway, the problem is that ts.getPoint changes pins YM and XP to input. You need to change them back to output after you call it, as is done in the example sketches:
Your code gives me the following compilation error :
Code: Select all
sketch_mar20a.ino: In function 'void setup()':
sketch_mar20a:72: error: 'class Adafruit_TFTLCD' has no member named 'readRegister'
Anyway, the problem is that ts.getPoint changes pins YM and XP to input. You need to change them back to output after you call it, as is done in the example sketches:
Code: Select all
void loop()
{
Point 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);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { // Si apreto un boto
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); // Recalculo les posicions X i Y
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
if (p.y >H1 && p.y<H5 ) {
if (p.x>X1 && p.x<X6){
if (p.x>X1 && p.x<X2){
if (p.y>H1 && p.y<H2){
Serial.println(p.x);
- tlerdrden
- Posts: 80
- Joined: Fri Nov 30, 2012 4:46 pm
Re: do not print in the screen
Brilliant!
I got the library from github. I guess it was an old library from Adafruit. Anyway, now it works with no problem, thank you very muchh!
I got the library from github. I guess it was an old library from Adafruit. Anyway, now it works with no problem, thank you very muchh!
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: do not print in the screen
Good luck! Looks like a fun project
- tlerdrden
- Posts: 80
- Joined: Fri Nov 30, 2012 4:46 pm
Re: do not print in the screen
Thanks again!
Let me share with you a video about the project
http://www.opiron.com/calcuino-video/163
See you!
Let me share with you a video about the project
http://www.opiron.com/calcuino-video/163
See you!
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Please be positive and constructive with your questions and comments.