为什么这段代码不能正确得到红外信号?
本帖最后由 zhangtory 于 2015-2-1 16:39 编辑为什么中途PIN2接地后不能接收到红外信号呢?
另外,在最开始就将PIN2接地就能收到红外信号,不接地后再接地也不能收到红外信号了,为什么啊?
以解决!
在输入口有电平变化的时候从新irrecv.enableIRIn(); 一下。
但是我不知道为什么。。。
#include <IRremote.h>
int RECV_PIN = 11; //recive pin
int LED_PIN = 13;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
unsigned int rawCode;
int bits;
void setup()
{
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
delay(2000);
digitalWrite(LED_PIN, LOW);
irrecv.enableIRIn(); // Start the receiver
pinMode(2, INPUT_PULLUP);
}
//send commend
void sendCode(){
irsend.sendRaw(rawCode, bits, 38);
Serial.print("sendRaw: ");
Serial.print(rawCode, HEX);
Serial.print(" | ");
Serial.println(bits);
delay(200);
}
//recive and record
void rec_ir(){
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
void loop() {
//delay(3000);
if(digitalRead(2) == LOW){
rec_ir();
}
if(digitalRead(2) == HIGH){
sendCode();
delay(1000);
}
}
在rec_ir();函数中加了print,发现是执行了 的,那应该就是红外库的原因吧!
有可能是什么问题?
谢谢啦~ 作为输入端应该有上拉电阻或下拉电阻。 林定祥 发表于 2015-1-31 17:19 static/image/common/back.gif
作为输入端应该有上拉电阻或下拉电阻。
在setup()中已经加了pinMode(2, INPUT_PULLUP); 代码更新了下,求助啊!
页:
[1]