Does anyone know how to wrap and or text using the U8G2 Libary? I know there are other libraries that do this for you, but I'd like to use U8G2.
Thank you!
My code's here for reference. It's not clean, but it works for now.
Does anyone know how to wrap and or text using the U8G2 Libary? I know there are other libraries that do this for you, but I'd like to use U8G2.
Thank you!
My code's here for reference. It's not clean, but it works for now.
You can do something like this:
void loop(void) {
u8g2_uint_t x;
u8g2.firstPage();
do {
// draw the scrolling text at current offset
x = offset;
u8g2.setFont(u8g2_font_inb30_mr); // set the target font
do { // repeated drawing of the scrolling text...
u8g2.drawUTF8(x, 30, text); // draw the scolling text
x += width; // add the pixel width of the scrolling text
} while( x < u8g2.getDisplayWidth() ); // draw again until the complete display is filled
u8g2.setFont(u8g2_font_inb16_mr); // draw the current pixel width
u8g2.setCursor(0, 58);
u8g2.print(width); // this value must be lesser than 128 unless U8G2_16BIT is set
} while ( u8g2.nextPage() );
offset-=1; // scroll by one pixel
if ( (u8g2_uint_t)offset < (u8g2_uint_t)-width )
offset = 0; // start over again
delay(10); // do some small delay
}
The code is taken from https://github.com.
It is an excellent library, but it is can require a big amount of memory, fit very well on ESP8266 (tried on nodeMCU) / ESP32.
Of course on ESP32 it is faster.
Used for small OLED 0.98" screen.