UNPKG

rpi-ws281x

Version:
50 lines (35 loc) 1.31 kB
var ws281x = require('../index.js'); class Example { constructor() { this.config = {}; // Number of leds in my strip this.config.leds = 24; // 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.strip = 'grb'; // 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, green = 0, 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();