Project 1 - Light-sensitive Lights

Note: At one point this was an entry in an Instructables contest.

 

This is a set of lights that smoothly changes colour and pattern depending on the amount of light in the room.
 
Apologies for the video - you'll need to view it in HD, and even then you may not be able to make out all of the code.
 
You'll need:
 
I connected:
 
There's more information on controlling and wiring up the lights on the WS2811 page. The actual code you need to copy and paste in is:
 
function onInit() {
  SPI1.setup({baud:3200000, mosi:A7});
  C3.set(); // Pull the light sensor's potential divider up to 3.3v
}

onInit();
var light = 0.0; // an average

function getPattern() {    
  var lightInstant = analogRead(C1)*3;
  light = lightInstant*0.1 + light*0.9;
  var cols = [];
  for (var i=0;i<50;i++) {
     var c = (-Math.abs(i-25)*10) + light*1024 - 200;
     if (c<0) c=0;
     if (c>255) c=255;
     cols.push(c); 
     c = (-Math.abs(i-25)*10) + light*1024 - 450;
     if (c<0) c=0; 
     if (c>255) c=255;
     cols.push(c);
     c = (-Math.abs(i-25)*10) + light*1024 - 600; 
     if (c<0) c=0; 
     if (c>255) c=255;
     cols.push(c);
  }
  return cols;
}

function doLights() {    
  SPI1.send4bit(getPattern(), 0b0001, 0b0011);
}

setInterval(doLights, 50);