arduino+蓝牙+LCD屏显示接收到的信息

#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 = "";
      }
  

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值