clean serial output
[Arduino] / rpi_promini / rpi_promini.ino
index fa139a0..81964a3 100644 (file)
@@ -86,6 +86,7 @@ void setup() {
   Serial.begin(9600);
   mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2  
   mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
+  mySwitch.setRepeatTransmit(repeat); // or change to be different for 433 and 315 MHz
 
   // DS18B20
   sensors.begin();
@@ -97,7 +98,7 @@ void setup() {
 
 int serial_pos = 0;
 char serial_data[2]; // socket (0-9), state (0-1)
-char binary_data[24];
+char binary_data[32];
 
 void loop() {
   if (mySwitch.available()) {
@@ -128,6 +129,13 @@ void loop() {
        LED_OFF
      } else
 
+     if ( input == 'R' ) {
+       Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
+       Serial.print("# send 315 binary ");
+       Serial.println( binary_data );
+       send_315( binary_data );
+     } else
+
     // light sockets at 315 Mhz
      if (input == 'a') {
        send_315("1000100110110000000000010");
@@ -146,7 +154,7 @@ void loop() {
        Serial.println(dht.getStatusString());
      }
 
-     if ( input >= 0x30 && input <= 0x39 ) {
+     if ( input >= 0x30 && input <= 0x39 && serial_pos < 2 ) {
        input = input - 0x30; // ASCII to number
        serial_data[serial_pos++] = input;
      } else {     
@@ -182,6 +190,26 @@ void loop() {
            on  ? mySwitch.send("001111110000000011000000")
                : mySwitch.send("001111110000000000000000");
            break;
+         case 5:
+/*
+               cca. 320Mhz 4 channel 4.8A 220V relay
+
+               A       1101001010011010011100010
+               B       1101001010011010011101000
+               C       1101001010011010011100100
+               D       1101001010011010011110000
+               off     1101001010011010011111000
+               on      1101001010011010011100110
+*/
+               switch ( on ) {
+                       case '0': send_315( "1101001010011010011111000" );
+                       case '1': send_315( "1101001010011010011100110" );
+                       case 'A': send_315( "1101001010011010011100010" );
+                       case 'B': send_315( "1101001010011010011101000" );
+                       case 'C': send_315( "1101001010011010011100100" );
+                       case 'D': send_315( "1101001010011010011110000" );
+                       default:  Serial.println("# ERROR: use 0-off 1-on A B C D");
+               }
          default:
            Serial.print("# invalid switch number ");
            Serial.println(serial_data[0], DEC);