哪个网站有免费空间新闻今天
我们如果实现简单的LCD的屏幕文字滚动其实也不难,但这里我们还是先用拿来主义。
首先,我们必须在类库管理器中找到LiquidCrystal的对应库文件,这里不再赘述。现在假定你已经成功安装了库文件了。那么我们可以开始看看其中的有关scrool的内置函数:
scrollDisplayLeft() //向左滚动
scrollDisplayRight() //向右滚动
autoscroll() //自动滚动开启
noAutoscroll() //关闭自动滚动
很显然这四个函数是有关LCD屏幕文字滚动控制的。而且利用前两个就能够满足我们左滚右滚的要求啦。
假定,我们使用的是4行20字符的LCD(LM044L)我们来看看实物连接图仿真:
看代码:
#include<LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() {// put your setup code here, to run once:lcd.begin(20,4);lcd.print("hello,world");delay(1000);
}void loop() {// put your main code here, to run repeatedly:for(int positionCounter=0;positionCounter<9;positionCounter++){lcd.scrollDisplayRight();delay(600);}for(int positionCounter=0;positionCounter<9;positionCounter++){lcd.scrollDisplayLeft();delay(600);}
我们的文字刚刚11个字符,那么对于20字符宽度的屏幕,我们设置左右滚动9刚好不出界。是不是实现起来很轻松啊。