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
I think that the value of available just determine if there is a message to receive or not.
-
Yes, looking at the source code of the library, it seems that
available()
returns false if no data has been received yet.Peter Bloomfield– Peter Bloomfield2014年11月21日 15:01:26 +00:00Commented Nov 21, 2014 at 15:01
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
-
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 smtuser1722245– user17222452020年03月22日 22:15:00 +00:00Commented Mar 22, 2020 at 22:15