Arduino 433 自定义接受

/*
  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();
  }
}

  

原文地址:https://www.cnblogs.com/kekeoutlook/p/8207103.html