For our very own AnyPixel.js board
Project uses a Teensy 3.2 board to control the WS2812 LED strip and buttons, using serial data to communicate.
To install the library, simply type this into your nearest console:
npm install nopixel
At this point, depending on the distribution, you may note that your computer is slightly unhappy. This is due to the fact that nopixel
relies on serialport
to get access to, well, the serial port. serialport
however, relies on node-gyp
which is notoriously hard to build. Therefore I recommend you go to https://github.com/nodejs/node-gyp#installation for your troubleshooting needs.
If installation of nopixel
still fails, please run
npm install serialport
- Flash the firmware found in
firmware/arduino_firmware
to the Teensy. For this you will need to install Teensyduino - Create a
config.json
following this template[{ "comPort": "/name/of/comPort", "baudRate": "BAUD_RATE" }]
- Run
node app.js
for the example app
This module supports node-canvas
. Simply create a 7x7 canvas, then export it to the board using
var data = ctx.getImageData(0,0,7,7);
nopixel.fromCanvas(data);
nopixel.update();
For a working example, look into examples/ConnectFour
All nopixel events, with the exception of ready
, sends back an object eventDetail
with the coordinates of the button press in the form of
var eventDetail = {
x: X-coordinate of the button press (0-6),
y: Y-coordinate of the button press (0-6),
index: Index of the button press (0-48)
}
Emits when established a connection with the board. Throws an error otherwise.
Emits when a button is pressed quickly - aka 'onButtonDown'. Pass an eventDetail
object.
Emits when a button is held down. Pass an eventDetail
object.
Emits when a button is released - aka 'onButtonUp'. Pass an eventDetail
object.
Emits the default state, when nothing is happening. Pass an eventDetail
object.
nopixel.setPixel(x, y, colorObj)
Where x,y denotes the coordinates on the board (0-6), and colorString is a valid tinyColor2
object. Examples includes string input ("black"
, "f0f0f6"
, "rgb (255, 0, 0)"
, "hsla(0, 100%, 50%, .5)"
), or RGB/RGBA/HSL/HSLA/HSV/HSVA objects ({ h: 0, s: 1, l: .5 }
)
nopixel.update()
aka render
. Pushes and set all changes to LEDs at the same time. This prevents multiple refresh calls to the board and saves clock cycles.
nopixel.clear()
Sets all pixels to black, essentially turning them off.
nopixel.fromCanvas(canvasBuffer)
node-canvas
integration. Takes in a Canvas buffer and send it to the LEDs.
nopixel.write(string, colorObj, scrollSpeed)
One of the two text writing functions. .write()
is used for anything more than a single letter, and will scroll the text in string
, in color colorObj
, looping indefinitely at a speed (delay between updates) scrollSpeed
.
Passes back a setInterval
object. To stop scrolling use the built-in clearInterval()
.
For more information check out the TextDisplay
example.
nopixel.writeLetter(letter, colorObj, x, y)
The other text writing function. As opposed to .write()
, .writeLetter()
as the name suggests, only prints one letter
at a time, in color colorObj
, starting at coordinates x
y
.
Fonts configuration is stored in letters.json
as two-dimentional arrays, with 1 as filled, and 2 as unfilled - feel free to change them as you see fit.
See commands.md
[ ] Emulator
[ ] Make an even bigger one!
[ ] Use pre-wired WS2812 instead of manually soldering wires
[ ] Utility buttons?
[ ] Flushed USB port
[ ] getPixelData() function