rpi-ws281x
Version:
55 lines (41 loc) • 1.29 kB
JavaScript
var ws281x = require('../index.js');
class Example {
constructor() {
this.config = {};
// Number of leds in my strip
this.config.leds = 169;
// Use DMA 10 (default 10)
this.config.dma = 10;
// Set full brightness, a value from 0 to 255 (default 255)
this.config.brightness = 255;
// Set the GPIO number to communicate with the Neopixel strip (default 18)
this.config.gpio = 18;
// The RGB sequence may vary on some strips. Valid values
// are "rgb", "rbg", "grb", "gbr", "bgr", "brg".
// Default is "rgb".
// RGBW strips are not currently supported.
this.config.stripType = 'grb';
// Apply a gamma correction to account for the non-linear brightness
// of the LEDs. A typical value is 2.2
this.config.gamma = 2.2;
// Configure ws281x
ws281x.configure(this.config);
}
run() {
// Create a pixel array matching the number of leds.
// This must be an instance of Uint32Array.
var pixels = new Uint32Array(this.config.leds);
// Create a fill color with red/green/blue.
var red = 255;
var green = 0;
var blue = 0;
var color = (red << 16) | (green << 8) | blue;
for (var i = 0; i < this.config.leds; i++) {
pixels[i] = color;
}
// Render to strip
ws281x.render(pixels);
}
}
var example = new Example();
example.run();