File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -387,13 +387,31 @@ int main() {
387387 "by the name of" ,
388388 " PICO"
389389 };
390-
390+ int max_lines = SSD1306_HEIGHT / 8 ; // Each line is 8px tall.
391391 int y = 0 ;
392- for (uint i = 0 ;i < count_of (text ); i ++ ) {
392+ for (uint i = 0 ; i < count_of (text ); i ++ ) {
393+ int line_number = i + 1 ;
393394 WriteString (buf , 5 , y , text [i ]);
394- y += 8 ;
395+ y += 8 ;
396+ // On the 32px-tall versions of SSD1306, we can't display
397+ // all the text at once. We need to display 4 lines at a time.
398+ bool is_end_of_screen = (line_number % max_lines ) == 0 ;
399+ if (is_end_of_screen ) {
400+ render (buf , & frame_area );
401+ sleep_ms (3000 );
402+ memset (buf , 0 , SSD1306_BUF_LEN );
403+ y = 0 ;
404+ }
405+ // If it's the last line...
406+ if (line_number == count_of (text )) {
407+ // And the last line is not a multiple of max_lines...
408+ if (line_number % max_lines != 0 ) {
409+ // Then we will have a little more text to display.
410+ render (buf , & frame_area );
411+ sleep_ms (3000 );
412+ }
413+ }
395414 }
396- render (buf , & frame_area );
397415
398416 // Test the display invert function
399417 sleep_ms (3000 );
You can’t perform that action at this time.
0 commit comments