|
433遙控器,我用庫RCSwitch里面接收例程,收到信號的value值是:
遙控器按鍵A:Received 5264652 / 24bit Protocol: 1
遙控器按鍵B:Received 5264688 / 24bit Protocol: 1
以上是串口讀取出的數(shù)據(jù)。
#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();
}
}
|
|