Debugging skills are vital. Without them you will get nowhere.
Please point out to me in which line of your code you have declared y1?
Debugging skills are vital. Without them you will get nowhere.
Please point out to me in which line of your code you have declared y1?
J-M-L: Thank you for continuing to work with me.
I don't understand your last reply. I have looked at these descriptions for the getTextBounds before your reply. They were no help to me.
I am trying to use the
getTextBounds (const String &str, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
function to support my text centering efforts.
I am using integers for the arguments to this function, not floating point.
I attach the business end of my sketch, where I try to print out the centered text, below.
// initialize the ILI9341 TFT library
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST, TFT_MISO);
int x1, w, h;
String buf;
void setup(void) {
Serial.begin(9600);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor (0, 75);
tft.setTextSize(2);
tft.print("Original Text Line"); // Print initial text line to display screen
// Try to print the string "Centered Text Line" with a
// direct statement call
buf = "Centered Text Line";
Serial.println(buf);
Serial.println(" ");
Serial.println(tft.width());
Serial.println(" ");
Serial.println(tft.height());
tft.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h); // only care about w
tft.setCursor( (tft.width() - w)/2, y_out);
tft.print(buf);
}
void loop() {}
When the statement:
tft.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h); // only care about w
is reached during compilation, I get the following error message:
"no matching function for call to 'Adafruit_ILI9341::getTextBounds(String&, int, int, int*, int*, int*, int*)'
"
I apologize for being so dense.
How should these statements associated with printing centered test be changed or added to to make this sketch work?
Best wishes
I don't want to buy too deeply into this thread, but there appears to be several days of fartarsing around what should be a simple problem resolved long ago. I think the library I use covers ILI9341and has a simple command for centering text. I would have imagined that is commonplace, so If yours really doesn't, you might consider looking elsewhere. Try Henning Karlsen's UTFT from RinkyDink, it just might save you from re-inventing the wheel. It's all there on p7 of the manual.
I have not used the command myself, but I assume it is what you want.
The compiler is being very picky about the pointers, possibly because int on an ESP32 is 32 bits. x1 and y1 need to be declared int16_t, w and h need to be declared uint16_t.
The error with the floating point results from the OP using y1 as a variable name. y1() is a function from the math.h library file, which apparently is being included somewhere during the compilation.
I meant don’t use floating point and autocorrect fixed it to don’t you…
I fixed it
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.