diff --git a/ssd1306_text.py b/ssd1306_text.py index fef4e73..f637bbb 100644 --- a/ssd1306_text.py +++ b/ssd1306_text.py @@ -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 +