2

I am trying to use this example code from the RCSwitch library:

/*
  Simple example for receiving

  https://github.com/sui77/rc-switch
*/

#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()) {
    Serial.print("Is avail");
    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();
  }
}

It seems like the mySwitch.available() is returning false, but since there seems to be no documentation for the library I don't know what it means.

So why is that?

I am trying to use this code on a A-Star 32U4 Micro, which supports Arduino code.

2 Answers 2

1

I think that the value of available just determine if there is a message to receive or not.

1
  • Yes, looking at the source code of the library, it seems that available() returns false if no data has been received yet. Commented Nov 21, 2014 at 15:01
0

Your code is OK. It seems that the transmitter's remote control frequency is different from the receiver. Both transmitters and receivers must have the same frequency. 433MHZ - TX with 433MHZ - RX 315MHZ - TX with 315MHZ - RX

1
  • HI,I checked,The wall switch is labeled with "433.92Mhz", reciever is ebay.co.uk/itm/…. It make me crazy :-( I have to miss smt Commented Mar 22, 2020 at 22:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.