测试环境:
Mac OS
Arduino UNO
Arudino 1.8.9
实现功能
IoT End-to-end system 的大作业,项目是其中一个部分,为了实现通过Rpi发送指令的一个红外的遥控器。
UNO与RPi用串口通信,UNO从Raspberry Pi 串口读取指令,然后编码发送与接收的一个简单Demo。
这里Rpi的代码尚未放出来,Rpi会发送“XY”的编码。指的就是X-设备,Y-指令。
说明
- 为了避免红外无法正确定向,发送了三次信号。(这里发送间隔delay时间太长了)
- 红外的编码没有科学依据,只是为了测试定的数据。
- Case 2到Case 5都没有定义,预留的位置。
- <IRremote.h>,在Arudino - tools - manage library
搜索安装。
/*
IRsend Test of IoT demo
Date:2019/12/28
Receive command from Rpi and test the IRremote demo.
PIN3 is defined in head file.
IRsend PIN can only be defined in head file.
Decode message,example:recData="XY",device = X, command = Y.
*/
#include <IRremote.h>
IRsend irsend; //Create IRsent objects
int device;
int command;
String recData = "";
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available() > 0)
{
recData += char(Serial.read());
delay(2);