Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
LPD8806-node
============
# lpd8806-async

Install.
Asynchronous Node.js library that implements the LPD8806 protocol.

npm install lpd8806
## Install

var LPD8806 = require('LPD8806');
LPD8806 = new LPD8806(32, '/dev/spidev0.0');
LPD8806.fillRGB(0, 0, 255);
npm install lpd8806-async

Available Funtions:
## Run

```
var LPD8806 = require('lpd8806-async');
var ledstrip = new LPD8806(32, '/dev/spidev1.0');

ledstrip.fillRGB(200,200,200);

//Available Funtions:

ledstrip.updateBrightness(0.5); //Value must be between 0.0 and 1.0
ledstrip.update(); //To write the new Buffer
ledstrip.fillRGB(0, 0, 255); //RED, GREEN, BLUE
ledstrip.fillHSV(0.0, 100.0, 100.0); //HSV Values
ledstrip.allOFF();
ledstrip.setPixel(new Color({r: 0, g: 0: b: 255}));
ledstrip.setPixelRGB(0, 0, 255); //RED, GREEN, BLUE
ledstrip.setPixelHSV(0.0, 100.0, 100.0) //HSV Values
ledstrip.setPixelOff(pixelNumber);
```

Check /examples for usage examples.
Feel free to contribute.


Special thanks to [pmdroid](https://github.com/pmdroid)

LPD8806.updateBrightness(0.5); //Value must Between 0.0 and 1.0
LPD8806.update(); //To write the new Buffer
LPD8806.fillRGB(0, 0, 255); //ROT, GREEN, BLUE
LPD8806.fillHSV(0.0, 100.0, 100.0); //HSV Values
LPD8806.allOFF();
LPD8806.setPixel(new Color({r: 0, g: 0: b: 255}));
LPD8806.setPixelRGB(0, 0, 255); //ROT, GREEN, BLUE
LPD8806.setPixelHSV(0.0, 100.0, 100.0) //HSV Values
LPD8806.setPixelOff(pixelNumber);


The MIT License (MIT)
Expand Down
9 changes: 0 additions & 9 deletions example.js

This file was deleted.

43 changes: 43 additions & 0 deletions examples/flash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var LPD8806 = require('LPD8806');

// npm install async
var async = require("async");

var leds = new LPD8806(96, '/dev/spidev1.0');

// Flash ledstrip by manipulation of the color brightness
function flash(r, g, b, speed){
var i = 0;
var step = speed;

function performStep(){
var level = 0.01,
dir = step;

async.whilst(function(){
return (level >= 0.0);
},function (callback) {
setTimeout(function(){
leds.setMasterBrightness(level);
leds.fillRGB(r,g,b);
if(level >= 0.99){
dir =- step;
}
level += dir;
callback();
},4);
}, function (err) {
return;
});
}
performStep();
}


// Fade color
flash(130,16,233, 0.01);

// Flash color
setTimeout(function(){
flash(130,16,233, 0.09);
}, 20000);
36 changes: 36 additions & 0 deletions examples/rainbow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var LPD8806 = require('LPD8806');
var ledCount = 96;
var leds = new LPD8806(ledCount, '/dev/spidev1.0');

/** process.nextTick to avoid blocking it all the time */
function rainbow(brightness){

var _step = 0;
var start = 0;

brightness = brightness || 1.0;
leds.setMasterBrightness(brightness);
var i = 0;

function performStep() {
var amt = 1;
for(var p = 0; p < ledCount; p++){
var color = (p + _step) % 384;
leds.setPixel(start + p, leds.wheel_color(color));
}
leds.update();
_step += amt;
var overflow = _step - 384;
if(overflow >= 0){
_step = overflow;
}

if (++i >= 384) {
return;
}
setTimeout(performStep, 80);
}
performStep();
}

rainbow(0.8);
51 changes: 0 additions & 51 deletions lib/Animations.js

This file was deleted.

22 changes: 10 additions & 12 deletions lib/LPD8806.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ var ledCount = 32,
c_order = ChannelOrder.GRB,
masterBrightness = 1.0,
buffer = [],
gamma = new Buffer(256),
spi = new SPI.Spi(device, {
'mode': SPI.MODE.MODE_0,
'chipSelect': SPI.CS.none,
'maxSpeed': 20000000
}, function(s){
s.open();
});

var LPD8806 = function(leds, dev){
gamma = new Buffer(256);


var LPD8806 = function(leds, dev, options){
options = options || {};
ledCount = leds || ledCount;
device = dev || device;

this.spi = new SPI.Spi(device, options, function(s){
s.open();
});

for(var i = 0; i < ledCount; i++){
buffer[i] = new Buffer([0x80, 0x80, 0x80]);
}
Expand Down Expand Up @@ -77,7 +75,7 @@ LPD8806.prototype.update = function(){
var _buffer = buffer.slice(0, buffer.length);
_buffer.push(new Buffer([0x00, 0x00, 0x00]));
_buffer.push(new Buffer([0x00]));
spi.write(Buffer.concat(_buffer));
this.spi.write(Buffer.concat(_buffer));
};


Expand Down Expand Up @@ -158,4 +156,4 @@ LPD8806.prototype.wheel_color = function(wheelpos){
return new Color({r: r, g: g, b: b});
};

module.exports = LPD8806;
module.exports = LPD8806;
19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{
"name": "lpd8806",
"version": "0.2.0",
"name": "lpd8806-async",
"version": "0.2.2",
"private": false,
"scripts": {
"start": "node example.js"
},
"dependencies": {
"spi": "*",
"color": "*",
"sleep": "*",
"socket.io": "*"
"color": "*"
},
"description": "LPD8806 Node library for the Raspberry Pi",
"description": "Non-blocking LPD8806 NodeJS general library",
"main": "./lib/LPD8806",
"devDependencies": {},
"repository": {
"type": "git",
"url": "https://github.com/pmdroid/LPD8806-node"
"url": "https://github.com/muzzley/LPD8806-node"
},
"keywords": [
"SPI",
Expand All @@ -28,9 +23,9 @@
"Raspberry",
"PI"
],
"author": "pmdroid",
"author": "pmdroid, v0od0oChild",
"license": "MIT License",
"bugs": {
"url": "https://github.com/pmdroid/LPD8806-node/issues"
"url": "https://github.com/muzzley/LPD8806-node/issues"
}
}
14 changes: 0 additions & 14 deletions server.js

This file was deleted.