|
| 1 | +#!/usr/bin/env python |
| 2 | +#----------------------------------------------------------------------------- |
| 3 | +# ex5_qwiic_serlcd_enable_cursor.py |
| 4 | +# |
| 5 | +# Simple Example demonstrating the enable and disable cursor controls on the SerLCD (Qwiic). |
| 6 | +# |
| 7 | +# This example prints "Hello World!" to the LCD and |
| 8 | +# uses the cursor() and noCursor() methods to turn |
| 9 | +# on and off the cursor. |
| 10 | +#------------
10000
------------------------------------------------------------ |
| 11 | +# |
| 12 | +# Written by SparkFun Electronics, August 2020 |
| 13 | +# |
| 14 | +# Ported from Arduino Library code with many contributions from |
| 15 | +# Gaston Williams - August 29, 2018 |
| 16 | +# |
| 17 | +# This python library supports the SparkFun Electroncis qwiic |
| 18 | +# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single |
| 19 | +# board computers. |
| 20 | +# |
| 21 | +# More information on qwiic is at https://www.sparkfun.com/qwiic |
| 22 | +# |
| 23 | +# Do you like this library? Help support SparkFun. Buy a board! |
| 24 | +# |
| 25 | +#================================================================================== |
| 26 | +# Copyright (c) 2020 SparkFun Electronics |
| 27 | +# |
| 28 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 29 | +# of this software and associated documentation files (the "Software"), to deal |
| 30 | +# in the Software without restriction, including without limitation the rights |
| 31 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 32 | +# copies of the Software, and to permit persons to whom the Software is |
| 33 | +# furnished to do so, subject to the following conditions: |
| 34 | +# |
| 35 | +# The above copyright notice and this permission notice shall be included in all |
| 36 | +# copies or substantial portions of the Software. |
| 37 | +# |
| 38 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 39 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 40 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 41 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 42 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 43 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 44 | +# SOFTWARE. |
| 45 | +#================================================================================== |
| 46 | +# Example 5 |
| 47 | +# |
| 48 | + |
| 49 | +from __future__ import print_function |
| 50 | +import qwiic_serlcd |
| 51 | +import time |
| 52 | +import sys |
| 53 | + |
| 54 | +def runExample(): |
| 55 | + |
| 56 | + print("\nSparkFun Qwiic SerLCD Example 5\n") |
| 57 | + myLCD = qwiic_serlcd.QwiicSerlcd() |
| 58 | + |
| 59 | + if myLCD.connected == False: |
| 60 | + print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ |
| 61 | + file=sys.stderr) |
| 62 | + return |
| 63 | + |
| 64 | + myLCD.setBacklight(255, 255, 255) # Set backlight to bright white |
| 65 | + myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. |
| 66 | + myLCD.clearScreen() |
| 67 | + myLCD.cursor() # Turn on the underline cursor |
| 68 | + |
| 69 | + time.sleep(1) # give a sec for system messages to complete |
| 70 | + myLCD.print("Hello World!") |
| 71 | + |
| 72 | + while True: |
| 73 | + # turn off the cursor |
| 74 | + print("Cursor OFF") |
| 75 | + myLCD.noCursor() |
| 76 | + time.sleep(1) |
| 77 | + |
| 78 | + # turn on the cursor |
| 79 | + print("Cursor ON") |
| 80 | + |
| 81 | + myLCD.cursor() |
| 82 | + time.sleep(1) |
| 83 | + |
| 84 | +if __name__ == '__main__': |
| 85 | + try: |
| 86 | + runExample() |
| 87 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 88 | + print("\nEnding Example 5") |
| 89 | + sys.exit(0) |
| 90 | + |
| 91 | + |
0 commit comments