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

Committer:
TheChrisyd
Date:
Sun Oct 12 10:05:01 2014 +0000
Revision:
1:9a4f690820b0
Parent:
0:4d96e547dc15
reverted transmit code back to arduino example CodeWords

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TheChrisyd 0:4d96e547dc15 1 #include "mbed.h"
TheChrisyd 0:4d96e547dc15 2 #include "RCSwitch.h"
TheChrisyd 0:4d96e547dc15 3
TheChrisyd 0:4d96e547dc15 4 // This Example should only do one of either transmit or receive
TheChrisyd 0:4d96e547dc15 5 //#define TRANSMIT
TheChrisyd 0:4d96e547dc15 6 #define RECEIVE
TheChrisyd 0:4d96e547dc15 7
TheChrisyd 0:4d96e547dc15 8 Serial pc(USBTX, USBRX); // tx, rx
TheChrisyd 0:4d96e547dc15 9 RCSwitch mySwitch = RCSwitch( p11, p21 ); //tx, rx
TheChrisyd 0:4d96e547dc15 10
TheChrisyd 0:4d96e547dc15 11 int main()
TheChrisyd 0:4d96e547dc15 12 {
TheChrisyd 0:4d96e547dc15 13 pc.printf("Setup");
TheChrisyd 0:4d96e547dc15 14 while(1) {
TheChrisyd 0:4d96e547dc15 15 #ifdef RECEIVE
TheChrisyd 0:4d96e547dc15 16 if (mySwitch.available()) {
TheChrisyd 0:4d96e547dc15 17
TheChrisyd 0:4d96e547dc15 18 int value = mySwitch.getReceivedValue();
TheChrisyd 0:4d96e547dc15 19
TheChrisyd 0:4d96e547dc15 20 if (value == 0) {
TheChrisyd 0:4d96e547dc15 21 pc.printf("Unknown encoding");
TheChrisyd 0:4d96e547dc15 22 } else {
TheChrisyd 0:4d96e547dc15 23 pc.printf("Received %d \n\r", mySwitch.getReceivedValue());
TheChrisyd 0:4d96e547dc15 24 pc.printf(" bit %d \n\r", mySwitch.getReceivedBitlength());
TheChrisyd 0:4d96e547dc15 25 pc.printf(" Protocol: %d \n\r", mySwitch.getReceivedProtocol());
TheChrisyd 0:4d96e547dc15 26 }
TheChrisyd 0:4d96e547dc15 27 mySwitch.resetAvailable();
TheChrisyd 0:4d96e547dc15 28 }
TheChrisyd 0:4d96e547dc15 29 #endif
TheChrisyd 0:4d96e547dc15 30 #ifdef TRANSMIT
TheChrisyd 0:4d96e547dc15 31 // Example: TypeA_WithDIPSwitches
TheChrisyd 0:4d96e547dc15 32 mySwitch.switchOn("11111", "00010");
TheChrisyd 0:4d96e547dc15 33 wait(1);
TheChrisyd 0:4d96e547dc15 34 mySwitch.switchOn("11111", "00010");
TheChrisyd 0:4d96e547dc15 35 wait(1);
TheChrisyd 0:4d96e547dc15 36
TheChrisyd 0:4d96e547dc15 37 // Same switch as above, but using decimal code
TheChrisyd 1:9a4f690820b0 38 mySwitch.send(5393, 24);
TheChrisyd 0:4d96e547dc15 39 wait(1);
TheChrisyd 1:9a4f690820b0 40 mySwitch.send(5396, 24);
TheChrisyd 0:4d96e547dc15 41 wait(1);
TheChrisyd 0:4d96e547dc15 42
TheChrisyd 0:4d96e547dc15 43 // Same switch as above, but using binary code
TheChrisyd 0:4d96e547dc15 44 mySwitch.send("000000000001010100010001");
TheChrisyd 0:4d96e547dc15 45 wait(1);
TheChrisyd 0:4d96e547dc15 46 mySwitch.send("000000000001010100010100");
TheChrisyd 0:4d96e547dc15 47 wait(1);
TheChrisyd 0:4d96e547dc15 48
TheChrisyd 0:4d96e547dc15 49 // Same switch as above, but tri-state code
TheChrisyd 0:4d96e547dc15 50 mySwitch.sendTriState("00000FFF0F0F");
TheChrisyd 0:4d96e547dc15 51 wait(1);
TheChrisyd 0:4d96e547dc15 52 mySwitch.sendTriState("00000FFF0FF0");
TheChrisyd 0:4d96e547dc15 53 wait(1);
TheChrisyd 0:4d96e547dc15 54 #endif
TheChrisyd 0:4d96e547dc15 55 }
TheChrisyd 0:4d96e547dc15 56 }