Clock minute padding

I’ve created a clock but for the time of 10:01 my dislay shows 10:1. I messed with the paddings but had no luck. Is adding the left 0 possible in Squareline or should it be done in the Arduino IDE on this line: lv_label_set_text(ui_minutes1, minute1);

1 Like

lv_label_set_text in LVGL itself doesn’t handle numbers in labels, it simply shows textual content. You should take care of creating that string in the exported code, as you probably do it already. You can do it like now, that is, creating a string first and setting that on the label, but lv_label_set_text_fmt() is the single-step preferred more convenient way, there you should specify the format of the timer to be something like “%2.2d” as printf format-specifier, padding and showing the 1st zero is ensured by the ‘2’ values. So your command would look like lv_label_set_text_fmt( ui_minutes1, “%2.2d”, minute1 );
(You could use a single label bat that would cause alignment differences between different numbers if they’re not monospace-type.)

That worked and thank you. My final code is:

itoa(rtc.getMinute(), minute, 10); 
    if(rtc.getMinute()<10)
    {
     char buf[10];
     sprintf(buf, "%02s", minute);
     lv_label_set_text(ui_minutes, buf);
    }
    else lv_label_set_text(ui_minutes, minute);
2 Likes