Skip to content

Commit

Permalink
Fix SSD1306 example to display all text on small (32px) screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayce Basques committed Aug 23, 2024
1 parent 9902d31 commit e0d8b62
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions i2c/ssd1306_i2c/ssd1306_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e0d8b62

Please sign in to comment.