【问题标题】:When I send a Bluetooth message I can't receive other IR codes当我发送蓝牙消息时,我无法接收其他 IR 码
【发布时间】:2018-02-15 16:10:39
【问题描述】:

我是 Arduino 新手,不知道如何解决这个问题。

当 Arduino 通过蓝牙接收到一个字符或我从遥控器发送另一个 IR 代码时,我想发送一个 IR 代码“通道”。

但如果我通过蓝牙发送 char 'a',程序不会捕获任何新的 IR 消息。

我正在使用连接到引脚 12、13 的 HC-06 蓝牙模块和连接到引脚 2 的 IR 接收器。

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <IRremote.h> 

IRsend irsend;
unsigned int channel[67] = { 9300, 4300, 700, 1400, 800, 1350, 800, 1400, 700, 1450, 700, 1450, 750, 1350, 800, 1350, 750, 1400, 750, 400, 750, 350, 800, 300, 800, 300, 800, 350, 750, 350, 750, 400, 700, 400, 750, 1400, 750, 350, 750, 350, 750, 350, 800, 1400, 750, 1400, 750, 350, 750, 400, 700, 350, 800, 1400, 750, 1350, 750, 1450, 750, 300, 800, 350, 800, 1350, 750, 1400, 750};
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;  
SoftwareSerial BT1(12,13);
char incomingChar = 0;

void setup() {
  irrecv.enableIRIn();
  Serial.begin(9600);
  BT1.begin(9600);
}

void loop() {
  if (irrecv.decode(&results)) {
    int hexen = results.value;
    Serial.println(hexen, HEX);
    Serial.print("\t");
    Serial.println(hexen, DEC);
    irrecv.resume();
    if(hexen == -16833) {
      Serial.print("Hello");
    }
  }
  if (BT1.available()) {
    incomingChar = BT1.read();
    Serial.print("->: ");
    Serial.println(incomingChar);
    if (incomingChar=='a') {
      Serial.print(" Send ");
      Send();
    }
    if (incomingChar=='s') {
      Serial.print("Test");
    }
  }
}

void Send() {
  irsend.sendRaw(channel,67,38);
  delay(40);
}

irsend.sendRaw的问题,还是蓝牙的某种冲突?

【问题讨论】:

    标签: bluetooth arduino infrared


    【解决方案1】:

    已解决,只需要重新启用红外接收器

    void Send() {
      irsend.sendRaw(channel,67,38);
      delay(40);
      irrecv.enableIRIn(); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 2019-02-21
      • 2014-01-30
      • 1970-01-01
      • 2018-12-01
      相关资源
      最近更新 更多