npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leddriver

v0.0.3

Published

a node.js library to control a SPI led driver (p.e adafruit leddriver) with your Raspberry Pi

Downloads

5

Readme

node-leddriver

This is a node.js library to control a SPI led driver.

I wrote this to control my Adafruit 24-Channel 12-bit PWM LED Driver using the TLC5947 with my Raspberry Pi. This should also work with different SPI devices or host systems but my examples referr to this configuration. It could also be used for other PWM modules like motor controls etc.

installation

npm install leddriver

initialization

var LEDDRIVER = require("leddriver");
var driver = new LEDDRIVER(24, 12);

parameters:

  • the number of channels your leddriver has
  • the bits per channel of your leddriver
  • (optional) the name of the SPI device (if omitted /dev/spidev0.0 as defined in node-simplespi )

directly setting values

driver.set(5, 819);

parameters:

  • the channelnumber to set (0 to number of channels - 1)
  • the direct value to set in the channel

This example sets the value of channel 5 to 500. The maximum allowed value depends on the bits per channel of your device. Since I am using a 12bit SPI device it has 3 hexadecimal digits per channel ("000" to "FFF"). In decimal this is a value between 0 and 4095.

percentage value setting

driver.pset(5, 0.2);
  • the channelnumber to set (0 to number of channels - 1)
  • the percentage to set in the channel (0 - 1)

This example sets the value of channel 5 to 0.2 * maximum value. In my 12bit example this has exactly the same result like the first example (0.2 * 4095 = 819) but it is far easier to use like this.

sending the values to your driver

driver.send();

This updates your led driver by sending the values.

example

var LEDDRIVER = require("leddriver");
var driver = new LEDDRIVER(24, 12);

driver.pset(0, 1);
driver.pset(1, 0);
driver.pset(2, 1);
driver.send();

setTimeout(function() {

    driver.pset(0, 0.5);
    driver.pset(1, 0.5);
    driver.pset(2, 0.5);
    driver.send();

}, 5000);

When running this example the LEDs connected to channel 0 and 2 should be fully turned on while channel 1 is off. After 5 seconds all the LEDs go to half brightness.

setting RGB-LEDs

The library also includes a helper for setting RGB-LEDs to a color defined in csslike hex style:

driver.setRGB("#e010ff", 0, 1, 2);

parameters:

  • the color to set as hexcode
  • the channel of the red LED
  • the channel of the green LED
  • the channel of the blue LED
  • (optional) the channel of the second blue LED

wiring the Raspberry Pi (example with adafruit led driver)

Connect your Pi like this to the LED driver:

| Raspberry Pi | led driver | |:------------:|:----------:| | GND | GND | | 5V or 3.3V (or external) | input V+ | | SCLK | input CLK | | MOSI | input DIN | | CE0 | input LAT |

Connect /OE on the LED driver to GND or to a GPIO of your choice (you can quickly turn off all LEDs by using a GPIO).

I am not responsible for any damages to your hardware. Use this at your own risk.