https://github.com/niklauslee/neopixel
Kaluma library for NeoPixel (ws2812) based on RP2 PIO (Programmable I/O)
https://github.com/niklauslee/neopixel
kaluma neopixel pio ws2812
Last synced: about 1 month ago
JSON representation
Kaluma library for NeoPixel (ws2812) based on RP2 PIO (Programmable I/O)
- Host: GitHub
- URL: https://github.com/niklauslee/neopixel
- Owner: niklauslee
- License: mit
- Created: 2022-02-17T03:57:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T02:31:02.000Z (about 2 years ago)
- Last Synced: 2025-04-12T04:12:15.608Z (about 1 month ago)
- Topics: kaluma, neopixel, pio, ws2812
- Language: JavaScript
- Homepage:
- Size: 142 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 |
# Install
```sh
npm install https://github.com/niklauslee/neopixel
```# Usage
```js
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`** `` The pin number connected to NeoPixel's input.
- **`length`** `` The number of NeoPixels.
- **`options`** `` Options.
- **`hz`** `` Frequency for control. Default: `800000` (800KHz).
- **`sm`** `` Id (0~7) of PIO state machine used to control. Default: `0`.Create an instance of NeoPixel driver.
### np.setPixel(index, color)- **`index`** `` Index of NeoPixel.
- **`color`** `` 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`** `` Index of NeoPixel.
- **Return** `` Color value (24-bit) of the NeoPixel.Returns the color value of the NeoPixel.
### np.color(r, g, b)
- **`r`** `` Red value (0~255).
- **`g`** `` Green value (0~255).
- **`b`** `` Blue value (0~255).
- **Returns** `` 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()`.