https://github.com/t-vk/ledmatrix
LED Matrix library for the NodeMCU firmware. Written in Lua. Works with WS2812, WS2812b, APA104, SK6812 and possibly more
https://github.com/t-vk/ledmatrix
led-matrix lua nodemcu rgb ws2812b
Last synced: 8 months ago
JSON representation
LED Matrix library for the NodeMCU firmware. Written in Lua. Works with WS2812, WS2812b, APA104, SK6812 and possibly more
- Host: GitHub
- URL: https://github.com/t-vk/ledmatrix
- Owner: T-vK
- Created: 2017-04-09T14:58:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-28T20:01:58.000Z (almost 9 years ago)
- Last Synced: 2025-03-04T01:49:13.323Z (about 1 year ago)
- Topics: led-matrix, lua, nodemcu, rgb, ws2812b
- Language: Lua
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LED Matrix Lua library for NodeMCU
## Description
This library allows you to easily set pixels in an RGB or RGBW LED matrix.
It is written in Lua and relies on the ws2812 module of NodeMCU.
## LED type support
- WS2812
- WS2812b
- APA104
- SK6812
- possibly more
Both RGB and RGBW!
## Set up
- Connect the data pin of your LED strip to GPIO pin 2.
- Make sure your power supply can supply enough current to drive your LED strip properly and reliably.
- Connect your 5V power supplly to your LED strip.
- Make sure your version of the NodeMCU firmware has the ws2812 module!!
- Upload all the lua files to your ESP8266 and include them in your init.lua, either by running dofile(...) on them or by literally pasting the file contents into `init.lua`.
- Make sure `ws2812.init()` has been called before calling `newMatrix()`
## Example
Turns the LEDs at x/y-position 1|1 and 10|10 white:
``` Lua
ws2812.init()
local ledMatrixInstance = newLedMatrix(10, 10, true, true, false, true, true)
ledMatrixInstance:set(1,1,255,255,255) -- x,y,red,green,blue
ledMatrixInstance:set(10,10,255,255,255)
ledMatrixInstance:show()
```
## Documentation
### newLedMatrix(width, height, isZigzag, isStartLedTop, isStartLedLeft, isRowLayout, isRgb)
Creates a new LedMatrix instance.
#### Parameters
- `width`: the width of your matrix (number of pixels)
- `height`: the height of your matrix (number of pixels)
- `isZigzag`: `true` if you have a zigzag layout, `false` if you have a progressive layout
A Zigzag layout looks like this:
```
X -> X -> X
|
X <- X <- X
|
X -> X -> X
```
A progressive layout looks like this:
```
X -> X -> X
_________|
|
X -> X -> X
_________|
|
X -> X -> X
```
- `isStartLedTop`: `true` if the first LED of your LED chain is in the very top row. `false` if it is in the very bottom row.
- `isStartLedLeft`: `true` if the first LED of your LED chain is in the very left column. `false` if it is in the very right column.
- `isRowLayout`: `true` if your LEDs are arranged in a row layout. `false` if your LEDs are arranged in a column layout.
- `isRgb`: `true` if your LEDs are RGB. `false` if your LEDs are RGBW.
#### Returns
- returns a new LedMatrix instance
### Methods and properties of LedMatrix instances
#### ledMatrixInstance:set(x,y,red,green,blue)
Parameters
- `x and y` The coordinates of the pixel you want to change
- `red, green and blue` The components of the color you want to set the LED to. Must be between 0 and 255. 0 being off and 255 being the brightest.
Returns
- No return value
#### ledMatrixInstance:show()
Send the new colors to the LEDs
Parameters
- No parameters
Returns
#### matrix
Instance of the matrix class (not documented yet)
#### ledCount
Number of LEDs in this matrix
#### bytesPerLed
Number of bytes that each LED takes (will be 3 for RGB and 4 for RGBW)
#### ledBuffer
Instance of a ws2812 buffer. Documented [here](https://nodemcu.readthedocs.io/en/master/en/modules/ws2812/#ws2812newbuffer)
You can use the buffer to create cool animations and also to find out which pixel is set to which color.