|
| 1 | +#!/usr/bin/env python |
| 2 | +#----------------------------------------------------------------------------- |
| 3 | +# ex15_qwiic_serlcd_message_enable.py |
| 4 | +# |
| 5 | +# This example demonstrates how to turn off the system messages displayed when |
| 6 | +# the user changes a setting. For instance 'Contrast: 5' or 'Backlight: 100%' is |
| 7 | +# no longer displayed. |
| 8 | +# |
| 9 | +# Note - This example and the disableSystemMessages() and enableSystemMessages() |
| 10 | +# commands are only supported on SerLCD v1.2 and above. |
| 11 | +# |
| 12 | +#------------------------------------------------------------------------ |
| 13 | +# |
| 14 | +# Written by SparkFun Electronics, August 2020 |
| 15 | +# |
| 16 | +# Ported from Arduino Library code with many contributions from |
| 17 | +# Gaston Williams - August 29, 2018 |
| 18 | +# |
| 19 | +# This python library supports the SparkFun Electroncis qwiic |
| 20 | +# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single |
| 21 | +# board computers. |
| 22 | +# |
| 23 | +# More information on qwiic is at https://www.sparkfun.com/qwiic |
| 24 | +# |
| 25 | +# Do you like this library? Help support SparkFun. Buy a board! |
| 26 | +# |
| 27 | +#================================================================================== |
| 28 | +# Copyright (c) 2020 SparkFun Electronics |
| 29 | +# |
| 30 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 31 | +# of this software and associated documentation files (the "Software"), to deal |
| 32 | +# in the Software without restriction, including without limitation the rights |
| 33 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 34 | +# copies of the Software, and to permit persons to whom the Software is |
| 35 | +# furnished to do so, subject to the following conditions: |
| 36 | +# |
| 37 | +# The above copyright notice and this permission notice shall be included in all |
| 38 | +# copies or substantial portions of the Software. |
| 39 | +# |
| 40 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 41 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 42 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 43 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 44 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 45 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 46 | +# SOFTWARE. |
| 47 | +#================================================================================== |
| 48 | +# Example 15 |
| 49 | +# |
| 50 | + |
| 51 | +from __future__ import print_function |
| 52 | +import qwiic_serlcd |
| 53 | +import time |
| 54 | +import sys |
| 55 | + |
| 56 | +def runExample(): |
| 57 | + |
| 58 | + print("\nSparkFun Qwiic SerLCD Example 15\n") |
| 59 | + print("\nType CTRL+C to end.\n") |
| 60 | + myLCD = qwiic_serlcd.QwiicSerlcd() |
| 61 | + |
| 62 | + if myLCD.connected == False: |
| 63 | + print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ |
| 64 | + file=sys.stderr) |
| 65 | + return |
| 66 | + |
| 67 | + myLCD.setBacklight(255, 255, 255) # bright white |
| 68 | + myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. |
| 69 | + myLCD.begin() # call this for default settings (no |
| 70 | + myLCD.leftToRight() |
| 71 | + myLCD.noCursor() |
| 72 | + time.sleep(1) # give a sec for system messages to complete |
| 73 | + |
| 74 | + myLCD.disableSystemMessages() # Now whenever you change a system setting like Contrast, |
| 75 | + # SerLCD will not display the setting. This makes changing the setting faster, and also |
| 76 | + # invisible to the user. |
| 77 | + |
| 78 | + #myLCD.enableSystemMessages() # This will re-enable the printing of system messages |
| 79 | + |
| 80 | + myLCD.clearScreen() |
| 81 | + myLCD.print("Hello World!") |
| 82 | + |
| 83 | + counter = 0 |
| 84 | + |
| 85 | + while True: |
| 86 | + # do something that would normally cause a system message |
| 87 | + # let's change color of backlight values every other count value |
| 88 | + if (counter % 2) == 0: |
| 89 | + myLCD.setBacklight(255, 0, 0) |
| 90 | + else: |
| 91 | + myLCD.setBacklight(0, 255, 0) |
| 92 | + |
| 93 | + time.sleep(0.1) # give it a sec to change backlight |
| 94 | + |
| 95 | + print("counter: %d" % counter) |
| 96 | + myLCD.setCursor(0,1) |
| 97 | + myLCD.print(str(counter)) |
| 98 | + counter = counter + 1 |
| 99 | + time.sleep(1) |
| 100 | + |
| 101 | +if __name__ == '__main__': |
| 102 | + try: |
| 103 | + runExample() |
| 104 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 105 | + print("\nEnding Example 15") |
| 106 | + sys.exit(0) |
| 107 | + |
| 108 | + |
0 commit comments