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

rpi-matrix

v1.0.72

Published

Raspberry Pi RGB Matrix addon for Node

Downloads

75

Readme

rpi-matrix

A module for generating animations on a Raspberry PI connected to a RGB LED matrix display (See https://www.adafruit.com/product/607).

This module may be used in two modes, either simple pixel-mode or in canvas-mode which enables you to draw graphics using the HTML5 Canvas API https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API.

Before you install this, please read this https://github.com/hzeller/rpi-rgb-led-matrix and make sure you have the appropriate libraries installed on your Raspberry Pi.

This module also uses npm module canvas https://www.npmjs.com/package/canvas. Again, make sure your Raspberry is updated with the proper components to compile.

Installation

Make sure you have the libraries needed to build this module.

$ sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev 

Then, install as usual.

$ npm install rpi-matrix --save

Usage

var Matrix = require('rpi-matrix');
Matrix.configure({'led-cols':32, 'led-rows':32});

var matrix = new Matrix({mode:'pixel});

Initializing

This module supports (almost) all of the command line options available with the samples from H Zeller. See https://github.com/hzeller/rpi-rgb-led-matrix for details.

Make sure to call Matrix.configure. The following options are available.

  • led-rows
  • led-cols
  • led-row-addr-type
  • led-multiplexing
  • led-gpio-mapping
  • led-chain
  • led-parallel
  • led-pixel-mapper
  • led-brightness
  • led-pwm-bits
  • led-show-refresh
  • led-scan-mode
  • led-pwm-lsb-nanoseconds
  • led-pwm-dither-bits
  • led-slowdown-gpio
  • led-no-hardware-pulse
  • led-inverse
  • led-rgb-sequence

Static Members

  • Matrix.Canvas - Contains the canvas API (same as require('canvas'))
  • Matrix.Color - Contains the color API (same as require('color'))
  • Matrix.configure(config) - Initializes the hardware.

Constructor

new Matrix(config)

Constructs a new matrix object. The config argument must contain the following values.

  • mode - Specifies mode, either pixel or canvas

Example

var Matrix = require('rpi-matrix');
var path = require("path");

Matrix.Canvas.registerFont(path.join(__dirname, './fonts/Verdana.ttf'), { family: 'what-ever' });
Matrix.configure({'led-cols':32, 'led-rows':32});

class Sample extends Matrix {

    run() {
        var ctx = this.canvas.getContext('2d');

        ctx.font = 'bold 16px Verdana';
        ctx.fillStyle = 'blue';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        ctx.fillText('X', this.width / 2, this.height / 2);

        this.render();

        setTimeout(() => {}, 3000);
    }
};

var sample = new Sample({mode:'canvas'});
sample.run();

Pixel Mode

When used in pixel mode the following methods are available

Methods

  • clear() - Clears the matrix, all pixels off
  • fill(color) - Fills entire matrix with a color
  • setPixel(x, y, color) - Set pixel at specified position
  • getPixel(x, y) - Returns color at specified location
  • setPixelRGB(x, y, r, g, b) - Sets a pixel using RGB colors
  • setPixelHLS(x, y, h, l, s) - Sets a pixel using HLS colors
  • render([image], [options]) - Renders the current pixels (or specified image) to the matrix. The options parameter may contain blend or scroll values. See source code for details.
  • RGB(r, g, b) - Returns a RGB color as an integer
  • HLS(h, l, s) - Returns a HLS color as an integer
  • sleep(milliseconds) - Helper function. Sleep the number of milliseconds specified.

Member Variables

  • mode - Specifies the matrix mode. Either pixel or canvas.
  • width - Specifies the width of the display
  • height - Specifies the height of the display
  • pixels - An array (Uint32Array) representing the pixels.

Canvas Mode

You may also construct a Matrix object in canvas mode. This gives you the ability to do more advanced graphics by using the HTML5 canvas API (or close to it) thanks to the npm module canvas https://www.npmjs.com/package/canvas. For more information about the Canvas API visit https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API.

Example

var Matrix = require('rpi-matrix');
Matrix.configure({'led-cols':32, 'led-rows':32});
var matrix = new Matrix({mode:'canvas'});
...

When used in canvas mode the following methods are available

Methods

  • render([image], [options]) - Renders the current canvas (or specified image) to the matrix. The options parameter may contain blend or scroll values. See source code for details.
  • sleep(milliseconds) - Helper function. Sleep the number of milliseconds specified.

Member Variables

  • mode - Specifies the matrix mode. Either pixel or canvas.
  • width - Specifies the width of the display
  • height - Specifies the height of the display
  • canvas - The canvas used.

Simple Example using Canvas Mode

var Matrix = require('rpi-matrix');
Matrix.configure({'led-cols':32, 'led-rows':32});

class Sample extends Matrix {

    run() {
        var ctx = this.canvas.getContext('2d');

        ctx.fillStyle = 'blue';
        ctx.fillRect(0, 0, this.width, this.height);

        this.render();
        setTimeout(() => {}, 3000);
    }
};

var sample = new Sample({mode:'canvas'});
sample.run();

Simple Example using Fonts in Canvas Mode

var Matrix = require('rpi-matrix');
var path = require("path");

Matrix.Canvas.registerFont(path.join(__dirname, '../fonts/Verdana.ttf'), { family: 'what-ever' });

class Sample extends Matrix {

    run() {
        var ctx = this.canvas.getContext('2d');

        ctx.font = 'bold 16px Verdana';
        ctx.fillStyle = 'blue';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        ctx.fillText('X', this.width / 2, this.height / 2);

        this.render();

        setTimeout(() => {}, 3000);
    }
};
var sample = new Sample({mode:'canvas', width:32, height:32});
sample.run();

The example above displays the letter 'X' centered on the display. To use fonts not already installed on you Raspberry Pi, make sure to call Matrix.Canvas.registerFont() before any graphics are drawn.

See https://github.com/meg768/rpi-matrix/tree/master/examples/scripts for more examples.