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

Update ssd1306_text.py #6

Open
wants to merge 1 commit into
base: master
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
15 changes: 15 additions & 0 deletions ssd1306_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ def add_text(x, y, text, draw=1):
set_pos(x * 5, y)
ind0 = x * 10 + y * 128 + 1
i2c.write(ADDR, b'\x40' + screen[ind0:ind + 1])

def add_sentence(words):
''' print each word on its own line centered on the screen
if the number of characters in the word exceed the number
of columns on the screen, then indicate so with an asterisk

caller of this method is responsible for clearing the screen
'''
row_count = 0
for word in words.split():
if len(word) <= 12:
add_text(int((12-len(word))/2), row_count % 4, word)
else:
add_text(0, row_count % 4, word[:11] + "*")
row_count = row_count +