From 75265c7662c5bc3f3544f62e8354a41ae1be0a88 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 25 Jan 2015 22:04:32 +0100 Subject: [PATCH 1/1] added 4th socket and cleanup code --- rpi_promini/rpi_promini.ino | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/rpi_promini/rpi_promini.ino b/rpi_promini/rpi_promini.ino index f9065f3..3b4fc00 100644 --- a/rpi_promini/rpi_promini.ino +++ b/rpi_promini/rpi_promini.ino @@ -146,38 +146,34 @@ void loop() { Serial.print(serial_data[0], DEC); Serial.print(" state: "); Serial.println(serial_data[1] ? "on" : "off"); - serial_pos = 0; - if ( serial_data[1] ) { // on - switch ( serial_data[0] ) { + + byte on = serial_data[1]; + + // switches, 433 Mhz set of 3 + switch ( serial_data[0] ) { case 1: - mySwitch.send("110101011101010000001100"); - break; + on ? mySwitch.send("110101011101010000001100") + : mySwitch.send("110101011101010000000011"); + break; case 2: - mySwitch.send("110101010111010000001100"); + on ? mySwitch.send("110101010111010000001100") + : mySwitch.send("110101010111010000000011"); break; case 3: - mySwitch.send("110101010101110000001100"); + on ? mySwitch.send("110101010101110000001100") + : mySwitch.send("110101010101110000000011"); break; - default: - Serial.print("invalid switch on number "); - Serial.println(serial_data[0], DEC); - } - } else { // off - switch ( serial_data[0] ) { - case 1: - mySwitch.send("110101011101010000000011"); - break; - case 2: - mySwitch.send("110101010111010000000011"); - break; - case 3: - mySwitch.send("110101010101110000000011"); + case 4: + on ? mySwitch.send("001111110000000011000000") + : mySwitch.send("001111110000000000000000"); break; default: - Serial.print("invalid switch off number "); + Serial.print("invalid switch on number "); Serial.println(serial_data[0], DEC); - } - } + } + + // reset for later + serial_pos = 0; } } } -- 2.20.1