     }
   }
 
-  if(finish) {
+  // Old fade mechanism
+  /*if(finish) {
     // Sets all lamps to fade to a random color
     for (int lamp = 0; lamp < 4; lamp++) {
       lamps[lamp].fade(10000, colors[random(0, 215)]);
     }
+  }*/
+}
+
+void controller() {
+  // Read controll data from the serial port to decide what to do with the lamps
+  if(Serial.available() > 0) {
+    delay(100);
+
+    // Setup variables for control
+    unsigned char ctrl = Serial.read();
+    int selected_lamp = 5; // As 4 should be the higest needed value.
+    int r,g,b;
+
+    // Lamp select
+    selected_lamp = (ctrl & 224) >> 5;
+    
+    // Mode select
+    ctrl = ctrl & 31; // Remove the selector bits
+       
+    if (ctrl == 0) {
+      // Set color for lamp(s)
+      Serial.println("Set Color");
+      char cols[3];
+      Serial.readBytes(cols,3);
+      
+      int col[] = {cols[0],cols[1],cols[2]};
+      for(int i = 0; i < 3; i++) {
+        col[i] = col[i] < 0 ? col[i] + 256 : col[i];
+      }
+      if (selected_lamp < 4) {
+        lamps[selected_lamp].setColor(col);
+      }
+      else {
+        for(int lamp = 0; lamp < 4; lamp++) {
+          lamps[lamp].setColor(col);
+        }
+      }
+    }
+    else if (ctrl == 1) {
+      //Fade to color for lamp(s)
+      char cols[4];
+      Serial.readBytes(cols,4);
+      int col[] = {cols[0],cols[1],cols[2]};
+      for(int i = 0; i < 3; i++) {
+        col[i] = col[i] < 0 ? col[i] + 256 : col[i];
+      }
+      Serial.print("Fade Color:");
+      Serial.print(col[0]);
+      Serial.print("-");
+      Serial.print(col[1]);
+      Serial.print("-");
+      Serial.println(col[2]);
+      int fade_time = cols[3];
+      
+      if (selected_lamp < 4) {
+        lamps[selected_lamp].fade(fade_time*100,col);
+      }
+      else {
+        for(int lamp = 0; lamp < 4; lamp++) {
+          lamps[lamp].fade(fade_time*100,col);
+        }
+      }
+    }
+    else {
+      Serial.println("Ooops");
+      
+    }
+    
   }
 }
 

RGBLamp lamps[4];
int colors[216][3];
int dayCols[20][3];

void setup() {
  

  lamps[2].create(8,9,10);
  lamps[3].create(11,12,13);

  setColors();
  
  for (int lamp = 0; lamp < 4; lamp++) {
    lamps[lamp].fade(3000, dayCols[10]);
  }
}

// This will carry out the fades and so on. These must be run each loop! (!!!)
