#include <Arduino.h>
#include <RCSwitch.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRutils.h>
#define RECV_PIN 14 // 红外接收器 引脚
IRrecv IRR(RECV_PIN); // 红外遥控接收器 引脚
IRsend irsend(4); // 红外遥控发射对象
decode_results results; // 储存接收到的红外遥控信息
const uint32_t KDS = 0x32A650AF; // 打开关闭电视
const uint32_t JJYL = 0x32A6A857; // 电视音量调高一点
const uint32_t JYL = 0x32A638C7; // 电视音量调低一点
RCSwitch mySwitch = RCSwitch();
#define FRT 25 // 设置无线模块 发射 管脚变量
#define FRR 26 // 设置无线模块 接收 管脚变量
int WEI = 24; //无线模块 发射24位
const unsigned long AKEY = 0x720B12;//0x720B12,0x1D50D2,0x20FC42
void setup()
{
Serial.begin(9600); // 串口0波特率
Serial2.begin(9600); // 串口2波特率
pinMode(LED_BUILTIN, OUTPUT); // 设置LED引脚为输出模式
IRR.enableIRIn(); // 启动红外接收器
irsend.begin(); // 启动红外发射器
mySwitch.enableReceive(FRR); // 设置接收管脚
mySwitch.enableTransmit(FRT); // 设置FS管脚
delay(50);
}
void ledkz() // led闪烁一次
{
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
void HW_js()
{
if (IRR.decode(&results))
{
serialPrintUint64(results.value, HEX);
Serial.println("");
ledkz(); // led闪烁一次
IRR.resume(); // 恢复接收下一个红外遥控信号
}
delay(100);
}
void HW_fs() // 串口控制红外发射
{
while (Serial.available() > 0)
{
char val = Serial.read();
Serial.println(val);
if (val == 'B')
{
mySwitch.send(AKEY, 24);
delay(1000);
Serial.println(AKEY);
ledkz(); // led闪烁一次
}
}
}
void SU_03T() // 语音控制红外发射
{
while (Serial2.available() > 0)
{
int serialData = Serial2.read();
Serial.println(serialData, HEX); // 然后通过串口监视器输出read函数读取的信
switch (serialData)
{
case 0xA1: // 打开关闭电视
irsend.sendNEC(KDS);
ledkz();
break;
case 0xA3: // 电视音量调高一点
for (int i = 0; i < 10; i++)
{
irsend.sendNEC(JJYL);
delay(100);
}
ledkz();
break;
case 0xA4: // 电视音量调低一点
for (int i = 0; i < 10; i++)
{
irsend.sendNEC(JYL);
delay(100);
}
ledkz();
break;
}
}
}
void loop()
{
HW_js();
HW_fs();
SU_03T();
if (mySwitch.available()) {
Serial.print("读取数据 ");
Serial.print( mySwitch.getReceivedValue() );//输出接收到的值
// AKEY=mySwitch.getReceivedValue();
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );//输出获取到的数据长度
//WEI=mySwitch.getReceivedBitlength();
Serial.print("bit ");
Serial.print("协议: ");
Serial.println( mySwitch.getReceivedProtocol() );//输出获取接收协议
mySwitch.resetAvailable();//重置可用的值
}
}
【离线语音+红外发射接收+433发射接收】
最新推荐文章于 2024-06-16 02:39:06 发布