Example 1 - Bitmap Example

examples/ex1_bitmap_bender.py
  1#!/usr/bin/env python
  2#-----------------------------------------------------------------------------
  3# ex1_bitmap_bender.py
  4#
  5# Simple Example for the Qwiic Micro OLED display
  6#------------------------------------------------------------------------
  7#
  8# Written by  SparkFun Electronics, May 2021
  9#
 10# This python library supports the SparkFun Electroncis qwiic
 11# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
 12# board computers.
 13#
 14# More information on qwiic is at https:# www.sparkfun.com/qwiic
 15#
 16# Do you like this library? Help support SparkFun. Buy a board!
 17#
 18#==================================================================================
 19# Copyright (c) 2021 SparkFun Electronics
 20#
 21# Permission is hereby granted, free of charge, to any person obtaining a copy
 22# of this software and associated documentation files (the "Software"), to deal
 23# in the Software without restriction, including without limitation the rights
 24# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 25# copies of the Software, and to permit persons to whom the Software is
 26# furnished to do so, subject to the following conditions:
 27#
 28# The above copyright notice and this permission notice shall be included in all
 29# copies or substantial portions of the Software.
 30#
 31# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 32# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 33# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 34# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 35# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 36# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 37# SOFTWARE.
 38#==================================================================================
 39# Example 1 - Simple example to display a bitmap on the Qwiic Micro OLED board.
 40#
 41
 42from __future__ import print_function
 43import qwiic_oled_base
 44import time
 45import sys
 46
 47
 48bender = [ \
 49  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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 0xFB, 0xF8, 0xFB, 0xFB, 0xFB, 0xFB, 0xF8, 0xFB, 0xFB,\
 71  0xFB, 0xFB, 0xFB, 0xF8, 0xFB, 0xFD, 0xFD, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,\
 72  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
 73]
 74
 75def runExample():
 76
 77  #  These three lines of code are all you need to initialize the
 78  #  OLED and print the splash screen.
 79
 80  #  Before you can start using the OLED, call begin() to init
 81  #  all of the pins and configure the OLED.
 82
 83
 84  print("\nSparkFun Micro OLED Bitmap Example\n")
 85  myOLED = qwiic_oled_base.QwiicOledBase()
 86  #  By default, the superclass/base Python package loads the parameters 
 87  #  for the Qwiic Micro OLED board.
 88
 89  if not myOLED.connected:
 90    print("The Qwiic Micro OLED device isn't connected to the system. Please check your connection", \
 91      file=sys.stderr)
 92    return
 93
 94  myOLED.begin()
 95
 96  #  clear(ALL) will clear out the OLED's graphic memory.
 97  myOLED.clear(myOLED.ALL) #  Clear the display's memory (gets rid of artifacts)
 98  
 99  #  Display buffer contents
100  myOLED.display()
101  time.sleep(3)
102
103  #  clear(PAGE) will clear the Arduino's display buffer.
104  myOLED.clear(myOLED.PAGE)  #  Clear the display's buffer
105
106  #  Display buffer contents
107  myOLED.display()
108  time.sleep(3)
109
110  #  Draw Bitmap
111  #  ---------------------------------------------------------------------------
112  #  Add bitmap to buffer
113  myOLED.draw_bitmap(bender)
114
115  #  To actually draw anything on the display, you must call the display() function.
116  myOLED.display()
117
118if __name__ == '__main__':
119  try:
120    runExample()
121  except (KeyboardInterrupt, SystemExit) as exErr:
122    print("\nEnding OLED bitmap Example")
123    sys.exit(0)