UNO+1602+IIC(SDA和SCL)实现滚动显示
好棒棒!不要考虑文本长短了!!!是这样子的:
多次执行显示命令
就这么简单!
程序:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C mylcd(0x3F ,16,2);
void setup()
{
mylcd.init();
mylcd.backlight();
}
void loop()
{
mylcd.setCursor(0, 0);
mylcd.print("ni hao ");
mylcd.setCursor(0, 1);
mylcd.print("wo shi ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("wo shi ");
mylcd.setCursor(0, 1);
mylcd.print("Ding Jiahui ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("Ding Jiahui ");
mylcd.setCursor(0, 1);
mylcd.print("zhe shi wo de ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("zhe shi wo de ");
mylcd.setCursor(0, 1);
mylcd.print("da huai dan ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("da huai dan ");
mylcd.setCursor(0, 1);
mylcd.print("di di ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("di di ");
mylcd.setCursor(0, 1);
mylcd.print("Ding Jiahao ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("Ding Jiahao ");
mylcd.setCursor(0, 1);
mylcd.print("ta te bie huai ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("ta te bie huai ");
mylcd.setCursor(0, 1);
mylcd.print("HIT HIM! ");
delay(2000);
mylcd.setCursor(0, 0);
mylcd.print("HIT HIM! ");
mylcd.setCursor(0, 1);
mylcd.print("Da Bian My Didi! ");
delay(2000);
}
使用说明:
把mylcd.print后面的括号换成自己的话。
红色是一个单位
单位的末尾要与下一个单位的开头一样。
文本少了就删,多了就再复制几个单位
最后留言:
有改进的请评论
为何不用String数组+for循环实现?;P
string dataStr = {"ni hao ", "wo shi ", "wo shi ", "......"}
for(byte for_num=0; for_num < sizeof(dataStr )/sizeof(string); for_num+=2)
{
mylcd.setCursor(0, 0);
mylcd.print(dataStr);
mylcd.setCursor(0, 1);
mylcd.print(dataStr);
delay(2000);
} 萌小狸宝宝 发表于 2022-7-4 22:54
为何不用String数组+for循环实现?
string dataStr = {"ni hao ", "wo shi ", ...
不会,本人小白;P
页:
[1]