Hi, im trying to print text on the 2.8 tft touch shield by adafruit
Using the following code i get errors:
spitftbitmap2.ino: In function 'void setup()':
spitftbitmap2:47: error: 'setCursor' was not declared in this scope
spitftbitmap2:48: error: 'setTextSize' was not declared in this scope
spitftbitmap2:49: error: 'print' was not declared in this scope
What i miss ?
//
//spitftbitmap2.ino
//
#include <Adafruit_GFX.h> // Core graphics library
#include "Adafruit_ILI9341.h" // Hardware-specific library
#include <SPI.h>
#include <SD.h>
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define SD_CS 4
void setup(void) {
Serial.begin(9600);
tft.begin();
tft.fillScreen(ILI9341_BLUE);
setCursor(100,100);
setTextSize(15);
print("Hello world");
}
void loop() {
}
GFX library, how to print text ? error
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 74
- Joined: Thu Feb 20, 2014 5:36 pm
Re: GFX library, how to print text ? error
SOLVED by adding tft.
tft.setCursor(100,100);
tft.setTextSize(15);
tft.print("Hello world");
QUESTION: HOW TO SET COLOR
setTextColor(color) <-- how the arg color is, ok is uint16_t color but i mean, hot to pass RED, BLUE, BLACK, WHITE (what values for each listed color)?
tft.setCursor(100,100);
tft.setTextSize(15);
tft.print("Hello world");
QUESTION: HOW TO SET COLOR
setTextColor(color) <-- how the arg color is, ok is uint16_t color but i mean, hot to pass RED, BLUE, BLACK, WHITE (what values for each listed color)?
-
- Posts: 74
- Joined: Thu Feb 20, 2014 5:36 pm
Re: GFX library, how to print text ? error
solved color:
HOW TO CLEAR THE LAST TEXT WRITTEN TO, i mean, i set a background bitmap, now i wany to write some text at position 50,50 the now i want to update text, so i wanjt to clear last text so i can write text again withouth having 2 texts, how to ?
HOW TO CLEAR THE LAST TEXT WRITTEN TO, i mean, i set a background bitmap, now i wany to write some text at position 50,50 the now i want to update text, so i wanjt to clear last text so i can write text again withouth having 2 texts, how to ?
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: GFX library, how to print text ? error
setTextColor() takes an optional second color value, which will be used as the background color. If you only send a text color, only the pixels in the letter get changed. If you send a background color, every pixel in the rectangle that contains the character will change.
The background color will erase any previous text written in the same rectangle as the new characters.
If your text varies in length, just create a rectangle of background color the width of your longest expected string and draw that before drawing any new text.
You don't have to call display.show() between the blanking rectangle and writing the text. You can do all your blanking and redrawing in the memory buffer, then send the completed output to the screen when you're done.
The background color will erase any previous text written in the same rectangle as the new characters.
If your text varies in length, just create a rectangle of background color the width of your longest expected string and draw that before drawing any new text.
You don't have to call display.show() between the blanking rectangle and writing the text. You can do all your blanking and redrawing in the memory buffer, then send the completed output to the screen when you're done.
-
- Posts: 74
- Joined: Thu Feb 20, 2014 5:36 pm
Re: GFX library, how to print text ? error
That solution will be fine is no background picture,
But as i have a background bitmap, if i use the seconds args to setTextColor, e.g. text white with bg black, then is a no way cause it paint over the background bitmap.
If i dont use the second parameter then its good for the first time i write, cause it7 writes with no background so the letters are well over my background, but again, if i send another command to write again in the ssame area then the letters are mixed.
How to solve that ?
this is serius if anyone want to use background images
The function print must remember old pixel values to set back again each time before it print
But as i have a background bitmap, if i use the seconds args to setTextColor, e.g. text white with bg black, then is a no way cause it paint over the background bitmap.
If i dont use the second parameter then its good for the first time i write, cause it7 writes with no background so the letters are well over my background, but again, if i send another command to write again in the ssame area then the letters are mixed.
How to solve that ?
this is serius if anyone want to use background images
The function print must remember old pixel values to set back again each time before it print
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: GFX library, how to print text ? error
If you want to use background images under text, you'll need to redraw the image (or at least the rectangle you want to display) every time you change the text.
The microcontroller in an Arduino isn't designed to be a graphics proecessing engine, and you have to be conscious of the harware limits whenever you do processing-intensive work.
The microcontroller in an Arduino isn't designed to be a graphics proecessing engine, and you have to be conscious of the harware limits whenever you do processing-intensive work.
Please be positive and constructive with your questions and comments.