433遥控器,我用库RCSwitch里面接收例程,收到信号的value值是:
遥控器按键A:Received 5264652 / 24bit Protocol: 1
遥控器按键B:Received 5264688 / 24bit Protocol: 1
以上是串口读取出的数据。
#include <RCSwitch.h>
int led=13;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
if(value==5264652){
digitalWrite(led,HIGH);
}
if(value==5264688){
digitalWrite(led,LOW);
}
mySwitch.resetAvailable();
}
}
以上是例程代码简单修改,就是按键A时,LED亮灯,按键B时,LED灭灯;
实际情况是LED不亮灯也不灭灯,哪位大侠帮我看看问题出在哪里?
我还是放上接收解码的例程吧:
/*
Simple example for receiving
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
mySwitch.resetAvailable();
}
}
|