Giter VIP home page Giter VIP logo

neopixel's Introduction

NeoPixel (ws2812)

Kaluma library for NeoPixel (ws2812) based on RP2 PIO (Programmable I/O)

This is a library to control NeoPixels (WS2812).

This supports only RP2-based boards (e.g. Raspberry Pi Pico) because it is based on PIO (Programmable I/O).

Wiring

Here is a wiring example.

Raspberry Pi Pico NeoPixel
VBUS PWR
GND GND
GP0 IN

wiring

Install

npm install https://github.com/niklauslee/neopixel

Usage

const {NeoPixel} = require('neopixel');
const np = new NeoPixel(0, 12); // 12 pixels on GPIO0
np.setPixel(0, np.color(255, 0, 0)); // red on the 1st pixel
np.setPixel(1, np.color(0, 255, 0)); // green on the 2nd pixel
np.show();

API

Class: NeoPixel

A class for NeoPixel driver.

new NeoPixel(pin, length, options)

  • pin <number> The pin number connected to NeoPixel's input.
  • length <number> The number of NeoPixels.
  • options <object> Options.
    • hz <number> Frequency for control. Default: 800000 (800KHz).
    • sm <number> Id (0~7) of PIO state machine used to control. Default: 0.

Create an instance of NeoPixel driver.

np.setPixel(index, color)

  • index <number> Index of NeoPixel.
  • color <number> Color value (24-bit) to set. You can use np.color(r, g, b) to get a color value from RGB.

Set color value to a NeoPixel. You have to call show() the color to be shown on NeoPixel.

np.getPixel(index)

  • index <number> Index of NeoPixel.
  • Return <number> Color value (24-bit) of the NeoPixel.

Returns the color value of the NeoPixel.

np.color(r, g, b)

  • r <number> Red value (0~255).
  • g <number> Green value (0~255).
  • b <number> Blue value (0~255).
  • Returns <number> Color value (24-bit).

Return a color value from RGB values.

np.clear()

Clear all NeoPixels by setting color to 0.

np.show()

Show the color values defined by setPixel() on NeoPixels.

Examples

  • ex_spinning.js : Circular spinning on NeoPixels by changing colors.

TODO

  • Assign id for PIO state machine automatically using StateMachine.getAvailableId().

neopixel's People

Contributors

haraldkubota avatar niklauslee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

haraldkubota

neopixel's Issues

colors are different from the python library

Hi Niklaus

Thank you for this library, I have lot's of fun with it, trying to get a 12 segment Neopixel Ring running. First I figured out how to do it with the Python library and now I have an issue when it comes to a bit more "complicated" colors like rgb(100,0,90). It works fine with colors like rgb(127,0,0) or rgb(255,255,255) but rgb(100,0,90) is not the same color with Python and with your library, it get's even worse when I fill the ring with a gradient. I have no idea wether this is a difference in your implementation for the Neopixels or if it has to do with something running in Kaluma but maybe you have an idea how to fix it :-)

neopixel

Let me know if I can test something for you.

Best regards,
Peter

brightness issue

hi๐Ÿ‘‹
rgb(1,1,1)
in python makes a very low brightness white
but in javascript output is very bright (90 is darker than 1 !)

in my case output is not compareable

any idea?

Error messages

Firstly, impressive project!
Secondly: am wondering how to debug projects.
Specifically, If I flash a file, say like this:

kaluma flash ./index.js --bundle

And that file has an error, it seems that there is no way to see those error messages,
ie: to log stderr or equiv, correct?

Is there some what to print those errors back to the REPL ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.