Example for the RCSwitch Library. In receive mode, this will receive messages from the remote and decide which protocol has been used for transmission. In transmit mode, this will cycle through different formats for sending codewords.

Dependencies:   RCSwitch mbed

/media/uploads/TheChrisyd/rcswicth_components.jpg

Revision:
0:4d96e547dc15
Child:
1:9a4f690820b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 12 10:01:46 2014 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "RCSwitch.h"
+
+// This Example should only do one of either transmit or receive
+//#define TRANSMIT
+#define RECEIVE
+
+Serial pc(USBTX, USBRX); // tx, rx
+RCSwitch mySwitch = RCSwitch( p11, p21 ); //tx, rx
+
+int main()
+{
+    pc.printf("Setup");
+    while(1) {
+#ifdef RECEIVE
+        if (mySwitch.available()) {
+
+            int value = mySwitch.getReceivedValue();
+
+            if (value == 0) {
+                pc.printf("Unknown encoding");
+            } else {
+                pc.printf("Received %d \n\r", mySwitch.getReceivedValue());
+                pc.printf(" bit %d \n\r", mySwitch.getReceivedBitlength());
+                pc.printf(" Protocol: %d \n\r", mySwitch.getReceivedProtocol());
+            }
+            mySwitch.resetAvailable();
+        }
+#endif
+#ifdef TRANSMIT
+        // Example: TypeA_WithDIPSwitches
+        mySwitch.switchOn("11111", "00010");
+        wait(1);
+        mySwitch.switchOn("11111", "00010");
+        wait(1);
+
+        // Same switch as above, but using decimal code
+        mySwitch.send(83029, 24);//5393
+        wait(1);
+        mySwitch.send(83028, 24);//5396
+        wait(1);
+
+        // Same switch as above, but using binary code
+        mySwitch.send("000000000001010100010001");
+        wait(1);
+        mySwitch.send("000000000001010100010100");
+        wait(1);
+
+        // Same switch as above, but tri-state code
+        mySwitch.sendTriState("00000FFF0F0F");
+        wait(1);
+        mySwitch.sendTriState("00000FFF0FF0");
+        wait(1);
+#endif
+    }
+}