测试环境:
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);
}
//Serial.println(recData);

使用Arduino UNO创建的红外遥控系统,通过Raspberry Pi发送指令,UNO接收并编码转发。在Mac OS环境下,配合Arduino 1.8.9 IDE进行开发。Rpi发送"XY"编码,代表特定设备和指令。由于红外定向限制,发送三次信号确保接收。项目中红外编码仅为测试数据,未涉及具体标准。依赖<IRremote.h>库,需在Arduino IDE中安装。

72

被折叠的 条评论
为什么被折叠?



