Skip to content

Commit 671b001

Browse files
author
Pete Lewis
committed
ex11 working
1 parent 76f7202 commit 671b001

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python
2+
#-----------------------------------------------------------------------------
3+
# ex11_qwiic_serlcd_text_direction.py
4+
#
5+
# This example demonstrates how to use leftToRight() and rightToLeft()
6+
# to change the where the next character will be printed.
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 11
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 11\n")
55+
myLCD = qwiic_serlcd.QwiicSerlcd()
56+
57+
if myLCD.connected == False:
58+
print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
59+
file=sys.stderr)
60+
return
61+
62+
myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
63+
myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
64+
myLCD.begin() # call this for default settings (no
65+
myLCD.leftToRight()
66+
myLCD.cursor()
67+
time.sleep(1) # give a sec for system messages to complete
68+
69+
thisChar = 'a'
70+
71+
while True:
72+
73+
if thisChar == 'j': # reverse directions at 'm'
74+
myLCD.rightToLeft() # go right for the next letter
75+
76+
if thisChar == 'q': # reverse again at 's'
77+
myLCD.leftToRight() # go left for the next letter
78+
time.sleep(1)
79+
80+
if thisChar > 'z': # reset at 'z'
81+
myLCD.home() # go to (0,0)
82+
myLCD.clearScreen() # clear screen
83+
thisChar = 'a' # start again at 0
84+
85+
myLCD.print(thisChar) # print the character
86+
time.sleep(0.5) # wait a second
87+
thisChar = chr(ord(thisChar) + 1) # increment the letter
88+
89+
if __name__ == '__main__':
90+
try:
91+
runExample()
92+
except (KeyboardInterrupt, SystemExit) as exErr:
93+
print("\nEnding Example 11")
94+
sys.exit(0)
95+
96+

qwiic_serlcd.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ def clearScreen(self):
261261
time.sleep(0.01)
262262
return result
263263

264+
# ----------------------------------
265+
# home()
266+
#
267+
# Send the home command to the display. This returns the cursor
268+
# to return to the beginning of the display, without clearing
269+
# the display.
270+
def home(self):
271+
"""
272+
Send the home command to the display. This returns the cursor
273+
to return to the beginning of the display, without clearing
274+
the display.
275+
276+
:return: Returns true if the I2C write was successful, otherwise False.
277+
:rtype: bool
278+
279+
"""
280+
result = self.specialCommand(LCD_RETURNHOME)
281+
time.sleep(0.01)
282+
return result
283+
264284
# ----------------------------------
265285
# setCursor()
266286
#
@@ -680,4 +700,4 @@ def noDisplay(self):
680700
681701
"""
682702
self._displayControl &= ~LCD_DISPLAYON
683-
return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
703+
return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)

0 commit comments

Comments
 (0)