/* Arduino light control of Everflourish RF 433.92 MHz based system. For details, see: http://hblok.net http://hblok.net/blog/posts/2013/02/19/home-automation-with-arduino-and-android/ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define OUT_PIN 2 // Timings in micro seconds #define SHORT_UP_0 567 #define LONG_UP_1 1134 #define DOWN_SPACE 680 #define UP_END 15000 const int PREAMBLE = {0x00}; const int OFF[] = {0x55}; const int ON[] = {0xaa}; const int light_array[][5] = { {}, // main {0x65, 0xa9, 0x46, 0x95, 0x67, }, {0x65, 0xa9, 0x46, 0x96, 0x96, }, {0x65, 0xa9, 0x46, 0x99, 0xa3, }, {0x65, 0xa9, 0x46, 0x9a, 0x61, }, // aux {0x65, 0xa9, 0x46, 0x95, 0xaa, }, {0x65, 0xa9, 0x46, 0x96, 0x53, }, {0x65, 0xa9, 0x46, 0x99, 0x62, }, {0x65, 0xa9, 0x46, 0x9a, 0xa1, }, }; void setup() { Serial.begin(9600); Serial.println("setup"); pinMode(OUT_PIN, OUTPUT); } void loop() { if (Serial.available() > 1) { int light_id = Serial.read() - '0'; int on = Serial.read() - '0'; Serial.print(light_id); Serial.println(on); for(int i = 0; i < 5; i++) { send(light_array[light_id], on); } //delay(500); } } void send(const int *light_data, boolean on) { digitalWrite(OUT_PIN, LOW); delayMicroseconds(LONG_UP_1); send_bytes(PREAMBLE, 1, 4); send_bytes(light_data, 5, 8); send_bytes(on ? ON : OFF, 1, 8); digitalWrite(OUT_PIN, HIGH); delayMicroseconds(DOWN_SPACE); digitalWrite(OUT_PIN, LOW); delayMicroseconds(UP_END); digitalWrite(OUT_PIN, HIGH); } void send_bytes(const int *bytes, int len_bytes, int len_bits) { for(int b = 0; b < len_bytes; b++) { int data_byte = bytes[b]; for(int i = len_bits - 1; i >= 0; i--) { digitalWrite(OUT_PIN, HIGH); delayMicroseconds(DOWN_SPACE); digitalWrite(OUT_PIN, LOW); int data_bit = ((data_byte >> i) & 1); if (data_bit == 0) { delayMicroseconds(SHORT_UP_0); } else { delayMicroseconds(LONG_UP_1); } } } }