From d134e1fedc6eeec42c4105101a9543600aa4fc69 Mon Sep 17 00:00:00 2001 From: tentpegbob Date: Sat, 7 Oct 2017 15:47:56 -0400 Subject: [PATCH] Update ssd1306_text.py adding functionality for adding sentences with center alignment --- ssd1306_text.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 +