Code Monkey home page Code Monkey logo

node-pixelpusher's Introduction

node-pixelpusher

A node.js module to interface with Heroic Robotics' Pixel Pusher LED controller.

Install

npm install pixelpusher

API

Load

var PixelPusher = require('pixelpusher');

Discover

var pp = new PixelPusher().on('discover', function(controller) {
  var timer = null;

  // inspect controller.params and controller.params.pixelpusher...

  controller.on('update', function() {
    console.log ({ updatePeriod  : this.params.pixelpusher.updatePeriod
                 , deltaSequence : this.params.pixelpusher.deltaSequence
                 , powerTotal    : this.params.pixelpusher.powerTotal
                 });
  }).on('timeout', function() {
    console.log('controller ' + controller.params.ipAddress + ' (' + controller.params.macAddress + '): timeout');

    if (!!timer) clearInterval(timer);
  });

  // every 1/2-second change the colors
  timer = setInterval(function() { refresh(controller); }, 500);
}).on('error', function(err) {
  console.log('oops: ' + err.message);
});

Refresh

var n = 0;
var refresh = function(controller) {
  var i, strips, x;

  strips = [];
  strips[0] = { number: 0, data: new Buffer(3 * controller.params.pixelpusher.pixelsPerStrip) };
  strips[0].data.fill(0x00);
  x = [ [ 0, 4, 8 ], [ 1, 5, 9 ], [ 2, 6, -1] ][n % 3];
  for (i = 0; i < controller.params.pixelpusher.pixelsPerStrip; i += 9) {
    strips[0].data[i + x[0]] = 0xff;
    strips[0].data[i + x[1]] = 0xff;
    strips[0].data[i + x[2]] = 0xff;
  }
   
  controller.refresh(strips);
  n++;
};

Formats

if (strip[x].flags & 0x1) {         // red, green blue, orange[3], white[3]

  // indicates that the actual number of pixels is pixelsPerStrip/3,
  // each pixel is encoded as 9 octets
  //     first three octets are R, G, and B
  //     next three octets is the orange value (three times)
  //     next three octets is the white  value (three times)

} else if (strip[x].flags & 0x2) { // wide pixels

  // indicates that the actual number of pixels is pixelsPerStrip/2,
  // each pixel is encoded as 6 octets: R >> 8, G >> 8, B >> 8, R & 0xff, G & 0xff, B & 0xff

} else {

  // each pixel is encoded as three octets: R, G, and B

}

node-pixelpusher's People

Contributors

mrose17 avatar

Watchers

ted kaemming avatar Matt Robenolt avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.