8000 ex7 scroll working · sparkfun/qwiic_serlcd_py@4b7ec11 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b7ec11

Browse files
author
Pete Lewis
committed
ex7 scroll working
1 parent cd48503 commit 4b7ec11

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

examples/ex7_qwiic_serlcd_scroll.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
#-----------------------------------------------------------------------------
3+
# ex7_qwiic_serlcd_scroll.py
4+
#
5+
# Simple example demonstrating the scroll controls on the SerLCD (Qwiic).
6+
#
7+
# This example prints "Hello World!" to the LCD and uses the
8+
# scrollDisplayLeft() and scrollDisplayRight() methods to scroll
9+
# the text.
10+
#------------------------------------------------------------------------
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 7
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 7\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+
# scroll 13 positions (string length) to the left
74+
# to move it offscreen left:
75+
for i in range(13):
76+
myLCD.scrollDisplayLeft() # scroll one position left
77+
time.sleep(0.15) # wait a bit
78+
79+
# scroll 29 positions (string length + display length) to the right
80+
# to move it offscreen right:
81+
for i in range(29):
82+
myLCD.scrollDisplayRight() # scroll one position right
83+
time.sleep(0.15) # wait a bit
84+
85+
# scroll 16 positions (display length + string length) to the left
86+
# to move it back to center:
87+
for i in range(16):
88+
myLCD.scrollDisplayLeft() # scroll one position left
89+
time.sleep(0.15) # wait a bit
90+
91+
time.sleep(1) # delay at the end of the full loop
92+
93+
if __name__ == '__main__':
94+
try:
95+
runExample()
96+
except (KeyboardInterrupt, SystemExit) as exErr:
97+
print("\nEnding Example 7")
98+
sys.exit(0)
99+
100+

qwiic_serlcd.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,35 @@ def noBlink(self):
484484
"""
485485
self._displayControl &= ~LCD_BLINKON
486486
return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
487+
488+
# ----------------------------------
489+
# scrollDisplayLeft()
490+
#
491+
# Scroll the display one or multiple characters to the left, without changing the text.
492+
def scrollDisplayLeft(self, count = 1):
493+
"""
494+
Scroll the display one or multiple characters to the left, without changing the text.
495+
496+
:param count: Number of character spaces you'd like to scroll
497+
498+
:return: Returns true if the I2C write was successful, otherwise False.
499+
:rtype: bool
500+
501+
"""
502+
return self.specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT, count)
503+
504+
# ----------------------------------
505+
# scrollDisplayRight()
506+
#
507+
# Scroll the display one or multiple characters to the right, without changing the text.
508+
def scrollDisplayRight(self, count = 1):
509+
"""
510+
Scroll the display one or multiple characters to the right, without changing the text.
511+
512+
:param count: Number of character spaces you'd like to scroll
513+
514+
:return: Returns true if the I2C write was successful, otherwise False.
515+
:rtype: bool
516+
517+
"""
518+
return self.specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT, count)

0 commit comments

Comments
 (0)
0