Hi Everyone.
How do I print a variable with the 7 segmentfont?
This prints nothing.
showmsgXY(5, 150, 1, &FreeSevenSegNumFont, value2);
Thanks.
Hi Everyone.
How do I print a variable with the 7 segmentfont?
This prints nothing.
showmsgXY(5, 150, 1, &FreeSevenSegNumFont, value2);
Thanks.
showmsgxy() expects a string
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg);
If you want to display an int value, just convert into a string e.g.
char buf[10];
showmsgXY(5, 180, 1, &FreeSevenSegNumFont, itoa(1234, buf, 10));
Or if you have several occasions for this, write a helper function:
void showvalXY(int x, int y, int sz, const GFXfont *f, int val)
{
char buf[7]; //big enough for -32768 and terminating NUL
showmsgXY(x, y, sz, f, itoa(val, buf, 10));
}
You need a bigger buffer for a long or a float. And obviously use ltoa() or dtostrf()
David.
Thanks David.
I got it working now.
Is the "&FreeSevenSegNumFont" by default GREEN and the color does not change ?
tft.setTextColor(YELLOW); >> Does not work.
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
int16_t x1, y1;
uint16_t wid, ht;
// tft.drawFastHLine(0, y, tft.width(), WHITE);
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(GREEN);
tft.setTextSize(sz);
tft.print(msg);
}
You could change the colour to YELLOW if you want.
The important thing is that the showmsgXY()
function changes font, colour and size. As you found from your other thread.
When you write a "helper" function you choose convenient arguments and behaviour that suits your sketch. You could save and restore the original font, colour and size if you wanted.
David.
Thanks David.
You are right ..works now , I was changing the color out side the function.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.