Skip to content

Aligning printed text to the right #2028

Answered by olikraus
ZivojinM asked this question in Q&A
Discussion options

You must be logged in to vote

Not tested:

void loop(void) {
        int x = 100 - (millis()/100)%101;
        String xs = String(x);
        u8g2.firstPage();
        do { 
           u8g2.setFont(u8g2_font_logisoso26_tn);
           u8g2.setCursor(34-u8g2.getStrWidth(xs.c_str()), 36);
           u8g2.println(xs.c_str());
        } while ( u8g2.nextPage() );      
}

Reference: https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/

Edit: fixed "getStrWidth"

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ZivojinM
Comment options

Comment options

You must be logged in to vote
1 reply
@ZivojinM
Comment options

Answer selected by ZivojinM
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants