#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//导入LCD的库
String readString; //定义一个变量用于接收收到的字符串
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//定义LCD大小及格式
void setup() {
// put your setup code here, to run once:
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight(); //点亮LCD背景
lcd.setCursor(0,0); //定位第一行
lcd.print("welcome !"); //显示在第一行的字符串
lcd.setCursor(0,1);
lcd.print(" JamesBin");
pinMode(13, OUTPUT); //定义13号引脚为输出引脚
Serial.begin(9600); //定义波特率
}
//定义一个LCD显示函数
void LCD()
{
lcd.init();
lcd.setCursor(0,0);
lcd.print("Successful!");
lcd.setCursor(0,1);
lcd.print(readString);
delay(100);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()) //当检测到有数据传入时进入while循环
{
delay(3);
char c = Serial.read(); //将读取到的数据传给C
readString += c; //将读取到的数据进行拼接
}
if (readString.length() > 0)
{
Serial.println(readString);
LCD();
if (readString == "1") {
digitalWrite(13, 1);
}
if (readString == "0")
{
digitalWrite(13, 0);
}
readString = "";
}
arduino+蓝牙+LCD屏显示接收到的信息
最新推荐文章于 2021-12-11 14:51:31 发布