1.1.0 • Published 4 years ago

neopixel v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

NeoPixel

This library enables the Adafruit NeoPixel control from a Node.js script through a TCP connection.

The server side has to be installed on an ESP8266/Arduino (or compatible) board.
The client side can work on any machine that runs Node.js.

Requirements

Setup

Example

const NeoPixel = require('neopixel');

const SERVER = process.env['SERVER'] || 'tcp://neopixel.local:800'
const PAUSE = parseInt(process.env['PAUSE']) || 1000

const neopixel = new NeoPixel()

;(async () => {
  try {
    let { pixels } = await neopixel.connect(SERVER)
    console.log('PIXELS ' + pixels)

    let pixel = 0
    while (1) {
      pixel = ++pixel % neopixel.pixels
      const { latency } = await neopixel.setPixels([{ pixel, r: 255, g: 0, b: 0 }], true)
      console.info(`latency=${latency}ms`)
      await NeoPixel.wait(PAUSE - latency)
    }
  } catch (e) {
    console.error(`Error occurred: [${e.code}] ${e.message}`)
    process.exit(1)
  }
})()

Reference

new NeoPixel()

const NeoPixel = require('neopixel')
const neopixel = new NeoPixel()

connect(tcpUri)

Connects client with the board and returns number of configured pixels.

const {latency, pixels} = await neopixel.connect('tcp://neopixel.local:800')

setPixels(arrayOfColors, reset=false)

Sets pixel colors. If reset, any other pixel is turned off.

const {latency} = await neopixel.setPixels([
    {pixel: 10, red: 255, green: 0, blue: 0},
    {pixel: 20, red: 0, green: 255, blue: 0},
], true)

// shorthand version
const {latency} = await neopixel.setPixels([
    {p: 10, r: 255, g: 0, b: 0},
    {p: 20, r: 0, g: 255, b: 0},
], true)

fill(color)

Sets every pixel with the same color.

const {latency} = await neopixel.fill({red: 255, green: 0, blue: 0})

// shorthand version
const {latency} = await neopixel.fill({r: 255, g: 0, b: 0})

off()

Turn of every pixel.

const {latency} = await neopixel.off()

Changelog

  • 0.x - Beta version
  • 1.0 - First official version
  • 1.1 - Migrates to gh-workflows; Upgrades deps; Deprecated Node 8

Contributors