board.on('ready', function () {
  this.digitalWrite(5, this.HIGH);
  var light = new Five.Sensor('P9_40'); //A1 in Arduino Mapping

  this.repl.inject({
    light: light
  });

  client.on('connected', function(){
    var strip = client.add_strip({
      length: 25
    });

    var pixels = [];

    light.scale([0, 255]).on('data', function(){
      pixels = [];
      for(var i = 0; i < 120; i++){
        pixels.push([this.value, this.value, this.value]);
      }
      client.put_pixels(strip.id, pixels);
    });
  });
});
// Connect to opc client
var client = new opc_client({
  address: 'localhost',
  port: 7890
});

client.on('connected', function() {   // Do this connected
  console.log("Connected");
  var strip = client.add_strip({
    length: xlen*ylen
  });

// Here's how you move the ball
  function moveBall() {
    grid[y*ylen+x] = bgnd;    // Turn off ball in present location
    x += xdir;                // Move in the current direction
    if(x<0 || x>xlen-1) {     // See if you have fallen off either edge
      x = xlen/2;             // If so, restart in middle
    }
    grid[y*ylen+x] = color;   // Draw ball in new location
    client.put_pixels(strip.id, grid);  // Display the grid
    setTimeout(moveBall, ms); // Schedule the next ball move
  }
  
  moveBall(); // Start the ball moving
  
});

client.connect(); // Connect to the OPC server and start things moving
client.on('connected', function(){
  var strip = client.add_strip({
    length: 100
  });

  var pixels = [
      [255, 255, 255],
      [0, 0, 0],
      [255, 0, 0],
      [0, 255, 0],
      [0, 0, 255],
      [255, 255, 255],
      [0, 0, 0],
      [255, 0, 0],
      [0, 255, 0],
      [0, 0, 255],
      [255, 255, 255],
      [0, 0, 0],
      [255, 0, 0],
      [0, 255, 0],
      [0, 0, 255],
      [255, 255, 255],
      [0, 0, 0],
      [255, 0, 0],
      [0, 255, 0],
      [0, 0, 255],
      [255, 255, 255],
      [0, 0, 0],
      [255, 0, 0],
      [0, 255, 0],
      [0, 0, 255]
  ],
    new_pixel;

  setInterval(function(){
    client.put_pixels(strip.id, pixels);
    new_pixel = pixels[0];
    pixels = pixels.slice(1);
    pixels.push(new_pixel);
  }, 200);
});