2 Example for receiving wirelss signals and sending them out based on serial input
4 Based on examples from RC-Swtich which this sketch uses
6 http://code.google.com/p/rc-switch/
11 RCSwitch mySwitch = RCSwitch();
15 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
17 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
19 Serial.print("press buttons on remote or send AB where A = socket (0..9), B = state (0 = off, 1 = on)\n");
23 char serial_data[2]; // socket (0-9), state (0-1)
26 if (mySwitch.available()) {
27 Serial.print(mySwitch.getReceivedBitlength());
28 Serial.print(" bits ");
29 Serial.println(mySwitch.getReceivedValue(), BIN);
30 mySwitch.resetAvailable();
32 if (Serial.available() > 0) {
33 char input = Serial.read();
34 if ( input >= 0x30 && input <= 0x39 ) {
35 input = input - 0x30; // ASCII to number
36 serial_data[serial_pos++] = input;
38 Serial.print("ignore: ");
39 Serial.println(input, HEX);
42 if ( serial_pos == 2 ) {
43 Serial.print("socket: ");
44 Serial.print(serial_data[0], DEC);
45 Serial.print(" state: ");
46 Serial.println(serial_data[1] ? "on" : "off");
48 if ( serial_data[1] ) { // on
49 switch ( serial_data[0] ) {
51 mySwitch.send("110101010111010000001100");
54 mySwitch.send("110101010111010000001100");
57 mySwitch.send("110101010101110000001100");
60 Serial.print("invalid switch on number ");
61 Serial.println(serial_data[0], DEC);
64 switch ( serial_data[0] ) {
66 mySwitch.send("110101011101010000000011");
69 mySwitch.send("110101010111010000000011");
72 mySwitch.send("110101010101110000000011");
75 Serial.print("invalid switch off number ");
76 Serial.println(serial_data[0], DEC);