22#-----------------------------------------------------------------------------
33# ex3_demo.py
44#
5- # Demo Example for an OLED Display
5+ # An example showing various features of the display driver for Qwiic OLED displays
66#------------------------------------------------------------------------
77#
88# Written by SparkFun Electronics, May 2021
3636# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3737# SOFTWARE.
3838#==================================================================================
39- # Example 3 - An example showing various features of the display driver
40- #
4139
4240import qwiic_oled
4341import time
@@ -189,6 +187,14 @@ def shapeExample(myOLED):
189187
190188 time .sleep (.2 )
191189
190+ def show_done (myOLED ):
191+ myOLED .set_font_type (1 )
192+ myOLED .clear (myOLED .PAGE )
193+ myOLED .set_cursor (0 , 0 )
194+ myOLED .print ("DONE!" )
195+ myOLED .display ()
196+ time .sleep (1 )
197+
192198#-------------------------------------------------------------------
193199def textExamples (myOLED ):
194200
@@ -271,6 +277,7 @@ def textExamples(myOLED):
271277 myOLED .print ("A1: " )
272278 myOLED .set_font_type (2 )
273279
280+ # Note: For the "narrow" display, we can only fit the above two lines, so A2 will not be seen.
274281 myOLED .print ("%.3d" % randint (0 ,255 ))
275282 myOLED .set_cursor (0 , 32 )
276283 myOLED .set_font_type (0 )
@@ -282,6 +289,11 @@ def textExamples(myOLED):
282289 time .sleep (.1 )
283290
284291 # Demonstrate font 3. 12x48. Stopwatch demo.
292+ if myOLED .get_lcd_height () < 48 :
293+ # The "narrow" display doesn't have enough height to fully display font 3 or 4 so we'll end the demo here.
294+ show_done (myOLED )
295+ return
296+
285297 myOLED .set_font_type (3 ) # Use the biggest font
286298 ms = 0
287299 s = 0
@@ -321,13 +333,7 @@ def textExamples(myOLED):
321333 myOLED .display ()
322334 time .sleep (1 )
323335
324- myOLED .set_font_type (1 )
325- myOLED .clear (myOLED .PAGE )
326- myOLED .set_cursor (0 , 0 )
327- myOLED .print ("DONE!" )
328- myOLED .display ()
329- time .sleep (1 )
330-
336+ show_done (myOLED )
331337
332338#-------------------------------------------------------------------
333339
0 commit comments