![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.
main.cpp
- Committer:
- TheChrisyd
- Date:
- 2014-10-12
- Revision:
- 0:4d96e547dc15
- Child:
- 1:9a4f690820b0
File content as of revision 0:4d96e547dc15:
#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 } }