Arduino与xbee模块点灯外加Grove-LCD RGB Backlight显示器

硬件部分多了Grove-LCD RGB Backlight模块

在Arduino模块添加LCD库文件时,LCD的库文件要直接放在Arduino的libraies的子文件夹下,不要文件夹套文件夹。要不然会提示多余库神马的。

连接的话,就是把lcd模块直接插在I2C上

其余都是在上个实验上的基础上完成

特别注意还有,运行时,Tx要与Rx短接,这样lcd才能从串口读数据,当然烧录程序是肯定要断开的,要不然烧不进去。

软件部分:主机程序改了一下,从机程序没有动

主机程序:

int button_open =4;//开灯按钮连在数字端口4
int button_close =5; //关灯按钮连在数字端口5
char flag;//定义“向从机发送LED灯亮灭标志”的变量
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
void setup()
{
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);//设置led的颜色,你可以随便设置,这里是红色
pinMode(button_open, INPUT); //设置按钮为输入模式
pinMode(button_close, INPUT);
Serial.begin(9600);//启动串口通信,波特率为9600b/s
}
void loop()
{
//如果亮灯按钮按下同时关灯按钮松开
if( digitalRead(button_open)==LOW&&digitalRead(button_close)==HIGH)
{
flag='a';
Serial.print(flag);//向从机发送灯亮标志
// Serial.println(flag);//如果用这条语句会使lcd显示玩a后显示一个奇怪的字符

lcd.clear();//lcd清屏
lcd.write(Serial.read());//读串口

}
//如果关灯按钮按下同时亮灯按钮松开
if(digitalRead(button_close)==LOW&&digitalRead(button_open)==HIGH)
{
flag='b';
Serial.print(flag);//向从机发送灯灭标志

// lcd.write(flag);
lcd.clear();
lcd.write(Serial.read());
}
delay(1000);//延时,等待数据发送成功
}

从机的程序没有变。

posted @ 2017-06-08 16:40  吴春旭  阅读(844)  评论(0编辑  收藏  举报