Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSD1306 example to display all text on small (32px) screens #527

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions i2c/ssd1306_i2c/ssd1306_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,24 @@ int main() {
};

int y = 0;
for (uint i = 0 ;i < count_of(text); i++) {
for (uint i = 0; i < count_of(text); i++) {
WriteString(buf, 5, y, text[i]);
y+=8;
y += 8;
// Height limit reached. Show some lines.
if (y == SSD1306_HEIGHT) {
render(buf, &frame_area);
sleep_ms(3000);
Copy link
Contributor Author

@kaycebasques kaycebasques Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what happens when you run this app is:

  1. Lines 0 to 3 get printed ("a long time ago on an oled display far far away")
  2. Wait 3s (this the sleep on 398)
  3. Lines 4 to 7 get printed ("live a small red raspberry by the name of PICO")
  4. Wait 3s (again the sleep on 398)
  5. The extra check on lines 404 to 407 doesn't run with the default text because y is reset to 0
  6. Wait another 3s (this is the extra sleep on line 409 we should remove)

Leaving the sleep on line 398 and 406 ensures that text always displays for exactly 3s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

memset(buf, 0, SSD1306_BUF_LEN);
y = 0;
}
}
// Check if there's any more text left to display.
if (y != 0) {
render(buf, &frame_area);
sleep_ms(3000);
}
render(buf, &frame_area);

// 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);
Expand Down
Loading