Presently, printing text to the OLED module requires an understanding of the (x,y) co-ordinate system to anchor the text, and requires an argument for text-colour (1=white, 0=black) eg:
display.text("Hello, World!", 0,0, 1) # print literal string at (0,0) with white colour
To remove the assumed-knowledge and make code less intimidating we can abstract to the concept of line numbers, and print in white by default. The new function could be
where n is the line number, and string is the user-string to display.
eg. the following code would print three strings across three lines.
display.print(0, "hello world")
display.print(1, "second line")
display.print(2, "third line")
Under the hood, print() will just wrap text(), where the line number is translated into the appropriate co-ordinate (0, n*height) where n is the line number and height is the height of a letter, plus line-spacing.
There's scope for print() to auto-increment the line number, so that text flows up the screen on each successive call to print()
This is a cute stretch-goal, but probably beyond requirements.
Presently, printing text to the OLED module requires an understanding of the (x,y) co-ordinate system to anchor the text, and requires an argument for text-colour (1=white, 0=black) eg:
To remove the assumed-knowledge and make code less intimidating we can abstract to the concept of line numbers, and print in white by default. The new function could be
where
nis the line number, andstringis the user-string to display.eg. the following code would print three strings across three lines.
Under the hood,
print()will just wraptext(), where the line number is translated into the appropriate co-ordinate(0, n*height)wherenis the line number andheightis the height of a letter, plus line-spacing.There's scope for
print()to auto-increment the line number, so that text flows up the screen on each successive call toprint()This is a cute stretch-goal, but probably beyond requirements.