This tiny function, written in python
, allows you to easily scroll text of any length in the LCD 16x2 of Adafruit, which only allows 16 characters per row.
#Install And Use
To use this function just download the file named ScrollLCD.py and in your code import it. It takes two obligatory parameters, lcd
and text
.
Example:
from Adafruit_CharLCD import Adafruit_CharLCD
from ScrollLCD import *
lcd = Adafruit_CharLCD()
lcd.begin(16,1)
# Some code here ...
text = "This text has more than 16 characters, but it will print pretty fine in the LCD!"
scroll(lcd, text)
# More code here ...
You can customize things like the pause between next scroll, how many repetitions or the pause between every repetition. Pass those values in the function (scroll(lcd, text, pause1, pause2, repetitions)
) or edit the defaults in the file.
What could you do now? I don't know.. maybe a program that shows you the latest tweet in your timeline in the LCD?
#Feedback This function needs lots of improvements, so feel free to collaborate. And of course, you can edit the code to fit your needings as you want. Things that should be corrected/added:
- Detecting spaces and trying to no split words.
- Detect new lines
\n
and apply them correctly.
Thanks for this - very useful code!
FYI I've made a change to a fork (https://gist.github.com/cscashby/ba1b403d138ea81a522d) which adds an encoding line to the top of the file - otherwise the compiler breaks for the non-ASCII character in line 2.