|
| 1 | +#!/usr/bin/env python |
| 2 | +#----------------------------------------------------------------------------- |
| 3 | +# ex12_qwiic_serlcd_console_input_to_display.py |
| 4 | +# |
| 5 | +# This example demonstrates how to take text input from the python console |
| 6 | +# and send it to the LCD. |
| 7 | +# |
| 8 | +#------------------------------------------------------------------------ |
| 9 | +# |
| 10 | +# Written by SparkFun Electronics, August 2020 |
| 11 | +# |
| 12 | +# Ported from Arduino Library code with many contributions from |
| 13 | +# Gaston Williams - August 29, 2018 |
| 14 | +# |
| 15 | +# This python library supports the SparkFun Electroncis qwiic |
| 16 | +# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single |
| 17 | +# board computers. |
| 18 | +# |
| 19 | +# More information on qwiic is at https://www.sparkfun.com/qwiic |
| 20 | +# |
| 21 | +# Do you like this library? Help support SparkFun. Buy a board! |
| 22 | +# |
| 23 | +#================================================================================== |
| 24 | +# Copyright (c) 2020 SparkFun Electronics |
| 25 | +# |
| 26 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 27 | +# of this software and associated documentation files (the "Software"), to deal |
| 28 | +# in the Software without restriction, including without limitation the rights |
| 29 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 30 | +# copies of the Software, and to permit persons to whom the Software is |
| 31 | +# furnished to do so, subject to the following conditions: |
| 32 | +# |
| 33 | +# The above copyright notice and this permission notice shall be included in all |
| 34 | +# copies or substantial portions of the Software. |
| 35 | +# |
| 36 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 37 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 38 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 39 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 40 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 41 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 42 | +# SOFTWARE. |
| 43 | +#================================================================================== |
| 44 | +# Example 12 |
| 45 | +# |
| 46 | + |
| 47 | +from __future__ import print_function |
| 48 | +import qwiic_serlcd |
| 49 | +import time |
| 50 | +import sys |
| 51 | + |
| 52 | +def runExample(): |
| 53 | + |
| 54 | + print("\nSparkFun Qwiic SerLCD Example 12\n") |
| 55 | + print("\nType CTRL+C to end.\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 |
| 66 | + myLCD.leftToRight() |
| 67 | + myLCD.noCursor() |
| 68 | + time.sleep(1) # give a sec for system messages to complete |
| 69 | + |
| 70 | + while True: |
| 71 | + |
| 72 | + # promt the user to input some text |
| 73 | + user_input = input("Please type something to display on the LCD: ") |
| 74 | + |
| 75 | + myLCD.clearScreen() # clear the screen |
| 76 | + |
| 77 | + myLCD.print(user_input) # print what the user just typed in |
| 78 | + |
| 79 | + time.sleep(0.5) # wait a second |
| 80 | + |
| 81 | +if __name__ == '__main__': |
| 82 | + try: |
| 83 | + runExample() |
| 84 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 85 | + print("\nEnding Example 12") |
| 86 | + sys.exit(0) |
| 87 | + |
| 88 | + |
0 commit comments