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 output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
28 mySwitch.resetAvailable();
30 if (Serial.available() > 0) {
31 char input = Serial.read();
32 if ( input >= 0x30 && input <= 0x39 ) {
33 input = input - 0x30; // ASCII to number
34 serial_data[serial_pos++] = input;
36 Serial.print("ignore: ");
37 Serial.println(input, HEX);
40 if ( serial_pos == 2 ) {
41 Serial.print("socket: ");
42 Serial.print(serial_data[0], DEC);
43 Serial.print(" state: ");
44 Serial.println(serial_data[1] ? "on" : "off");
46 if ( serial_data[1] ) { // on
47 switch ( serial_data[0] ) {
49 mySwitch.send("110101010111010000001100");
52 mySwitch.send("110101010111010000001100");
55 mySwitch.send("110101010101110000001100");
58 Serial.print("invalid switch on number ");
59 Serial.println(serial_data[0], DEC);
62 switch ( serial_data[0] ) {
64 mySwitch.send("110101011101010000000011");
67 mySwitch.send("110101010111010000000011");
70 mySwitch.send("110101010101110000000011");
73 Serial.print("invalid switch off number ");
74 Serial.println(serial_data[0], DEC);