|
|
本帖最后由 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[500];
- 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,发现是执行了 的,那应该就是红外库的原因吧!
有可能是什么问题?
谢谢啦~ |
|