Hi!
I am using the ollikraus u8g2 library in the u8x8 mode on an OLED Display. The system uses a Arduino nano.
I would like to output a number that can hold values from 0 to 100 (int).
If I do so, the library will left justify. It leaves me with the problem that when going from '10' to '9' the display will display a 90.
The library is total flickerfree when displaying variables- just that it cant take into account any formatting. At least I hevent´t found a way to do it.
So here is some code:
[color=#24292e]U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);[/color]
[color=#24292e]u8x8.begin();
u8x8.setPowerSave(0);
display();[/color]
And in my function:
u8x8.setFont(u8x8_font_amstrad_cpc_extended_r);
u8x8.setCursor(0, 0);
u8x8.drawString(0,20, String(pwmd).c_str());
Alternative I can use (the draw string does not output variables)
u8x8.print(pwmd);
BUT: When I go from 10 to 9 it will display a 90
I dont want to have 09, i would like to display 9 only.
How can I achieve this?
In a former discussion someone said use:
u8x8.drawString(0,20, " "); // 3 spacers to cover 100
but that would get me a lot of flickering when changing the value,
same with the clear() command.
I would like to format my string, but I cant get the library to accept any printf or sprintf commands. (u8x8.printf...does not work. So I tried:
char buffer [50];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
//u8x8.drawString(0,20, pwmd);
// printf ("Width trick: %*d \n", 5, 10);
u8x8.drawString(0,20, String(n).c_str())
But that does only output the pointer the string (13)- not the string itself.
I feel a bit givven up on this - I think somehow it is something that we all solved 100 times when working with LCD displays, but somehow I can´t get working on this OLED with the prominent u8g2 lib.
So maybe someone could guide me a bit?