Arduino 433 自定义接受

2018/01/05 22:24
阅读数 34
/*
  Simple example for receiving
  
  https://github.com/sui77/rc-switch/
*/

#include <RCSwitch.h>
#define led1 10  
#define led2 11  
RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
    pinMode(led1, OUTPUT);    
      pinMode(led2, OUTPUT);    
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {
    
    int value = mySwitch.getReceivedValue();
    
    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
      if (value ==17) { 
        if( digitalRead(led1)==0){
        digitalWrite(led1, HIGH);
        }
        else{
           digitalWrite(led1, LOW);
          }
        }
      if (value ==18) { 

         if( digitalRead(led2)==0){
        digitalWrite(led2, HIGH);
        }
        else{
           digitalWrite(led2, LOW);
          }
      
      
      }
      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();
  }
}

  

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部