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