简体   繁体   English

按下按钮后Arduino IR接收器不工作

[英]Arduino IR receiver doesn't work after pressed a button

I'm trying to make a simple program that can receive IR codes and at the same time send another IR code when I press on a button. 我正在尝试制作一个简单的程序,该程序可以接收IR代码,并在按下按钮时同时发送另一个IR代码。

My problem is: The IR receiver only works before I pressed a button. 我的问题是:IR接收器只能在按下按钮之前工作。 If I press the button, the "first if-line" doesn't work anymore. 如果我按下按钮,“第一条if-line”将不再起作用。

#include <IRremote.h>
IRsend irsend;

int RECV_PIN = 2;   //Transmitter pin (input)
IRrecv irrecv(RECV_PIN);  //TP-stuff
decode_results results;   //TP-stuff


void setup() {
  pinMode(9, INPUT);  //knapp 6, LEDIG
  pinMode(3, OUTPUT);  //IRSEND
  pinMode(2, INPUT); //tramsmititer pin
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver //TP
}

void loop() {

  if (irrecv.decode(&results)) {                   //Transmitter IR
    Serial.println(results.value, HEX);           //Transmitter IR

    irrecv.resume(); // Receive the next value    //Transmitter IR


  } else if (digitalRead(9) == LOW) {
    irsend.sendNEC(0x20DF8679, 32); //LEDIG
    Serial.println("LEDIG knapp");
    digitalWrite(9, HIGH);
    delay(400);

  }
}

Enable again the IR receiver after you send and IR message: 发送并发送IR消息后,再次启用IR接收器:

else if (digitalRead(9) == LOW) {
    irsend.sendNEC(0x20DF8679, 32); //LEDIG
    Serial.println("LEDIG knapp");
    digitalWrite(9, HIGH);
    delay(400);
    irrecv.enableIRIn();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM