|
| 1 | +#!/usr/bin/env python |
| 2 | +#----------------------------------------------------------------------------- |
| 3 | +# ex9_qwiic_serlcd_custom_character.py |
| 4 | +# |
| 5 | +# This example prints "I <heart> SerLCD!" and a little dancing man |
| 6 | +# to the LCD. |
| 7 | +# |
| 8 | +# Custom characters are recorded to SerLCD and are remembered even after power is lost. |
| 9 | +# There is a maximum of 8 custom characters that can be recorded. |
| 10 | +# |
| 11 | +#------------------------------------------------------------------------ |
| 12 | +# |
| 13 | +# Written by SparkFun Electronics, August 2020 |
| 14 | +# |
| 15 | +# Ported from Arduino Library code with many contributions from |
| 16 | +# Gaston Williams - August 29, 2018 |
| 17 | +# |
| 18 | +# Based on Adafruit's example at |
| 19 | +# |
| 20 | +# https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde |
| 21 | +# |
| 22 | +# This example code is in the public domain. |
| 23 | +# http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter |
| 24 | +# |
| 25 | +# Also useful: |
| 26 | +# http://icontexto.com/charactercreator/ |
| 27 | +# |
| 28 | +# This python library supports the SparkFun Electroncis qwiic |
| 29 | +# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single |
| 30 | +# board computers. |
| 31 | +# |
| 32 | +# More information on qwiic is at https://www.sparkfun.com/qwiic |
| 33 | +# |
| 34 | +# Do you like this library? Help support SparkFun. Buy a board! |
| 35 | +# |
| 36 | +#================================================================================== |
| 37 | +# Copyright (c) 2020 SparkFun Electronics |
| 38 | +# |
| 39 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 40 | +# of this software and associated documentation files (the "Software"), to deal |
| 41 | +# in the Software without restriction, including without limitation the rights |
| 42 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 43 | +# copies of the Software, and to permit persons to whom the Software is |
| 44 | +# furnished to do so, subject to the following conditions: |
| 45 | +# |
| 46 | +# The above copyright notice and this permission notice shall be included in all |
| 47 | +# copies or substantial portions of the Software. |
| 48 | +# |
| 49 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 50 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 51 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 52 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 53 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 54 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 55 | +# SOFTWARE. |
| 56 | +#================================================================================== |
| 57 | +# Example 9 |
| 58 | +# |
| 59 | + |
| 60 | +from __future__ import print_function |
| 61 | +import qwiic_serlcd |
| 62 | +import time |
| 63 | +import sys |
| 64 | + |
| 65 | +def runExample(): |
| 66 | + |
| 67 | + print("\nSparkFun Qwiic SerLCD Example 9\n") |
| 68 | + myLCD = qwiic_serlcd.QwiicSerlcd() |
| 69 | + |
| 70 | + if myLCD.connected == False: |
| 71 | + print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ |
| 72 | + file=sys.stderr) |
| 73 | + return |
| 74 | + |
| 75 | + myLCD.setBacklight(255, 255, 255) # Set backlight to bright white |
| 76 | + myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. |
| 77 | + myLCD.begin() # call this for default settings (no |
| 78 | + myLCD.leftToRight() |
| 79 | + time.sleep(1) # give a sec for system messages to complete |
| 80 | + |
| 81 | + # make some custom characters: |
| 82 | + heart = [ |
| 83 | + 0b00000, |
| 84 | + 0b01010, |
| 85 | + 0b11111, |
| 86 | + 0b11111, |
| 87 | + 0b11111, |
| 88 | + 0b01110, |
| 89 | + 0b00100, |
| 90 | + 0b00000] |
| 91 | + |
| 92 | + smiley = [ |
| 93 | + 0b00000, |
| 94 | + 0b00000, |
| 95 | + 0b01010, |
| 96 | + 0b00000, |
| 97 | + 0b00000, |
| 98 | + 0b10001, |
| 99 | + 0b01110, |
| 100 | + 0b00000] |
| 101 | + |
| 102 | + frownie = [ |
| 103 | + 0b00000, |
| 104 | + 0b00000, |
| 105 | + 0b01010, |
| 106 | + 0b00000, |
| 107 | + 0b00000, |
| 108 | + 0b00000, |
| 109 | + 0b01110, |
| 110 | + 0b10001] |
| 111 | + |
| 112 | + armsDown = [ |
| 113 | + 0b00100, |
| 114 | + 0b01010, |
| 115 | + 0b00100, |
| 116 | + 0b00100, |
| 117 | + 0b01110, |
| 118 | + 0b10101, |
| 119 | + 0b00100, |
| 120 | + 0b01010] |
| 121 | + |
| 122 | + armsUp = [ |
| 123 <
F438
/td> | + 0b00100, |
| 124 | + 0b01010, |
| 125 | + 0b00100, |
| 126 | + 0b10101, |
| 127 | + 0b01110, |
| 128 | + 0b00100, |
| 129 | + 0b00100, |
| 130 | + 0b01010] |
| 131 | + |
| 132 | + myLCD.createChar(0, heart) |
| 133 | + myLCD.createChar(1, smiley) |
| 134 | + myLCD.createChar(2, frownie) |
| 135 | + myLCD.createChar(3, armsDown) |
| 136 | + myLCD.createChar(4, armsUp) |
| 137 | + |
| 138 | + myLCD.setCursor(0,0) # set cursor to the top left |
| 139 | + |
| 140 | + # Print a message to the LCD. |
| 141 | + myLCD.print("I ") |
| 142 | + myLCD.writeChar(0) # Print the heart character, stored in location 0 |
| 143 | + myLCD.print(" SerLCD! ") |
| 144 | + myLCD.writeChar(1) # Print smiley |
| 145 | + |
| 146 | + while True: |
| 147 | + |
| 148 | + myLCD.setCursor(4,1) # column, row |
| 149 | + myLCD.writeChar(3) # print little man, arms down |
| 150 | + time.sleep(0.2) |
| 151 | + |
| 152 | + myLCD.setCursor(4,1) # column, row |
| 153 | + myLCD.writeChar(4) # print little man, arms up |
| 154 | + time.sleep(0.2) |
| 155 | + |
| 156 | +if __name__ == '__main__': |
| 157 | + try: |
| 158 | + runExample() |
| 159 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 160 | + print("\nEnding Example 9") |
| 161 | + sys.exit(0) |
| 162 | + |
| 163 | + |
0 commit comments