From 5932b7762899d5fb7c821470284923fa3e0f1fdd Mon Sep 17 00:00:00 2001 From: Kayce Basques Date: Thu, 22 Aug 2024 19:44:07 -0700 Subject: [PATCH 1/3] Fix SSD1306 example to display all text on small (32px) screens --- i2c/ssd1306_i2c/ssd1306_i2c.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/i2c/ssd1306_i2c/ssd1306_i2c.c b/i2c/ssd1306_i2c/ssd1306_i2c.c index 6be5ea42c..0ab7af9ca 100644 --- a/i2c/ssd1306_i2c/ssd1306_i2c.c +++ b/i2c/ssd1306_i2c/ssd1306_i2c.c @@ -387,13 +387,31 @@ int main() { "by the name of", " PICO" }; - + int max_lines = SSD1306_HEIGHT / 8; // Each line is 8px tall. int y = 0; - for (uint i = 0 ;i < count_of(text); i++) { + for (uint i = 0; i < count_of(text); i++) { + int line_number = i + 1; WriteString(buf, 5, y, text[i]); - y+=8; + y += 8; + // On the 32px-tall versions of SSD1306, we can't display + // all the text at once. We need to display 4 lines at a time. + bool is_end_of_screen = (line_number % max_lines) == 0; + if (is_end_of_screen) { + render(buf, &frame_area); + sleep_ms(3000); + memset(buf, 0, SSD1306_BUF_LEN); + y = 0; + } + // If it's the last line... + if (line_number == count_of(text)) { + // And the last line is not a multiple of max_lines... + if (line_number % max_lines != 0) { + // Then we will have a little more text to display. + render(buf, &frame_area); + sleep_ms(3000); + } + } } - render(buf, &frame_area); // Test the display invert function sleep_ms(3000); From 10b397a753e4e7c90fa73c4513eccbfecb395dd5 Mon Sep 17 00:00:00 2001 From: Kayce Basques Date: Sat, 31 Aug 2024 19:45:18 -0700 Subject: [PATCH 2/3] Simplify the new logic --- i2c/ssd1306_i2c/ssd1306_i2c.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/i2c/ssd1306_i2c/ssd1306_i2c.c b/i2c/ssd1306_i2c/ssd1306_i2c.c index 0ab7af9ca..b5bfb845f 100644 --- a/i2c/ssd1306_i2c/ssd1306_i2c.c +++ b/i2c/ssd1306_i2c/ssd1306_i2c.c @@ -387,30 +387,22 @@ int main() { "by the name of", " PICO" }; - int max_lines = SSD1306_HEIGHT / 8; // Each line is 8px tall. int y = 0; for (uint i = 0; i < count_of(text); i++) { - int line_number = i + 1; WriteString(buf, 5, y, text[i]); y += 8; - // On the 32px-tall versions of SSD1306, we can't display - // all the text at once. We need to display 4 lines at a time. - bool is_end_of_screen = (line_number % max_lines) == 0; - if (is_end_of_screen) { + // Height limit reached. Show some lines. + if (y == SSD1306_HEIGHT) { render(buf, &frame_area); sleep_ms(3000); memset(buf, 0, SSD1306_BUF_LEN); y = 0; } - // If it's the last line... - if (line_number == count_of(text)) { - // And the last line is not a multiple of max_lines... - if (line_number % max_lines != 0) { - // Then we will have a little more text to display. - render(buf, &frame_area); - sleep_ms(3000); - } - } + } + // Check if there's any more text left to display. + if (y != 0) { + render(buf, &frame_area); + sleep_ms(3000); } // Test the display invert function From c965bdc078d73bde6b4a28a5d1d19bed5ac1fbb2 Mon Sep 17 00:00:00 2001 From: Kayce Basques Date: Sun, 1 Sep 2024 19:58:36 -0700 Subject: [PATCH 3/3] Restore blank line and remove extra sleep --- i2c/ssd1306_i2c/ssd1306_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i2c/ssd1306_i2c/ssd1306_i2c.c b/i2c/ssd1306_i2c/ssd1306_i2c.c index b5bfb845f..cb467cda4 100644 --- a/i2c/ssd1306_i2c/ssd1306_i2c.c +++ b/i2c/ssd1306_i2c/ssd1306_i2c.c @@ -387,6 +387,7 @@ int main() { "by the name of", " PICO" }; + int y = 0; for (uint i = 0; i < count_of(text); i++) { WriteString(buf, 5, y, text[i]); @@ -406,7 +407,6 @@ int main() { } // Test the display invert function - sleep_ms(3000); SSD1306_send_cmd(SSD1306_SET_INV_DISP); sleep_ms(3000); SSD1306_send_cmd(SSD1306_SET_NORM_DISP);