I have this bit of code. It works as written. It draws next char in array as first char of line, and each iteration shortens the displayed chars string by -1. BUT, this is opposite of what I want to do. i want to draw each array char after the last one as if someone is typing on the screen.... I tried a few things. No textwrite in the u8g2 wiki..
I tried modifying x position to match new char draw call, but did not work . I would like to draw just the 'next' char in the array in sequence (0 to sizeof array) rather than redrawing the whole char array and clearing the screen each time...
can someone point me in correct direction ? Thank you
here is link to wiki:
Simple code:
Code:
#include <U8g2lib.h>
U8G2_SSD1309_128X64_NONAME0_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 12, /* cs=*/ 11, /* dc=*/ 10, /* reset=*/ 9);
void setup(void) {
u8g2.begin();
}
void loop(void) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
char load[] = "LOADING...";
for (char *p = load; *p ; p++) {
u8g2.drawStr(20, 20, p); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
delay(500);
u8g2.clearDisplay() ;
}
}
Wow!! Thx PaulRB. I made a few tiny corrections and now it works. I kinda see how you changed position and selected the char to go into new position. Appreciate the help!!
Curious: So why would you not point '*p' to the array element in the 'for' loop? seems like it would save a line of code......
#include <U8g2lib.h>
U8G2_SSD1309_128X64_NONAME0_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 12, /* cs=*/ 11, /* dc=*/ 10, /* reset=*/ 9);
void setup(void) {
u8g2.begin();
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
}
void loop(void) {
char load[] = "LOADING...";
for (int p = 0; p < strlen(load) ; p++) {
u8g2.clearBuffer(); //clear buffer here
char c = load[p];
load[p] = '\n'; //changed null terminator (NOTE: EDITED FROM '\0' which chopped off one element!
u8g2.drawStr(20, 20, load); // write something to the internal memory
load[p] = c;
u8g2.sendBuffer(); // transfer internal memory to the display
delay(500);
}
}