control using serial port
[Arduino] / light_sockets / light_sockets.ino
index 67b957a..3d48c9e 100644 (file)
@@ -1,16 +1,28 @@
 #define TX_PIN 7
 #define LED_PIN 13
 
-char *code = "1000100110110000000000010";
-//char *code = "1011001001011111000000010";
+/*
+codes for my light sockets:
+
+1000100110110000000000010
+1011001001011111000000010
+
+sniffed with rtl-sdr
+*/
 
 void setup() {
    pinMode(LED_PIN, OUTPUT);
    pinMode(TX_PIN, OUTPUT);
+   
+   Serial.begin(9600);
+   Serial.println("1 or 2 to turn light sockets");
 }
 
-void loop() {
 
+void send(char *code) {
+  Serial.print("send ");
+  Serial.println(code);
+  
   // we have to send same signal at least two times
   for(int repeat = 0; repeat < 5; repeat++ ) {
     
@@ -32,6 +44,19 @@ void loop() {
     delayMicroseconds(2000); // guess
   }
 
-  digitalWrite(LED_PIN, LOW);  
-  delay(3000);
+  digitalWrite(LED_PIN, LOW);
+}
+
+void loop() {
+  if(Serial.available()) {
+    int in = Serial.read();
+    if (in == '1') {
+      send("1000100110110000000000010");
+    } else if (in == '2') {
+      send("1011001001011111000000010");
+    } else {
+      Serial.print("ignored ");
+      Serial.println(in);
+    }
+  }
 }