espruino-adafruit-led-backpack
This is a driver that closely mirrors the Adafruit's LED Backpack Library.
This package currently works with Adafruit 8x8 and 16x8 Single Color LED Backpacks.
- 8x8 0.8" (872, 871, 870)
- 8x8 1.2" (1049, 1052, 1051, 1050, 1614, 1632, 1857, 1854, 1855, 1856)
- 16x8 1.2" (2044, 2038, 2037, 2040, 2041, 2039, 2043, 2042, 2035, 2036, 2052, 2054)
- 16x8 LED Matrix Driver Backpack (1427)
This library was tested on on the Small 1.2" 8x8 Ultra Bright Square White LED Matrix + Backpack, PRODUCT ID: 1857 and on the 16x8 1.2" Ultra Bright Square Green LED Matrix + Backpack.
This doesn't work with the 7-Segment backpacks.
Example Code for 8 x 8 Matrix
To use this library in the Espruino Web IDE you need to go to Settings > Communications > Check 'Load modules from NPM (BETA)'
.
Here's some example code that mirrors the Adafruit's example code for the 8x8 Matrix example code for Arduino.
var Matrix8x8 = require("espruino-adafruit-led-backpack").Matrix8x8;
var matrix = new Matrix8x8({scl:B6, sda:B7, address:0x70, brightness: 0});
var smileBmp = [
0b00111100,
0b01000010,
0b10100101,
0b10000001,
0b10100101,
0b10011001,
0b01000010,
0b00111100
],
neutralBmp = [
0b00111100,
0b01000010,
0b10100101,
0b10000001,
0b10111101,
0b10000001,
0b01000010,
0b00111100
],
frownBmp = [
0b00111100,
0b01000010,
0b10100101,
0b10000001,
0b10011001,
0b10100101,
0b01000010,
0b00111100
];
function delay(time) {
var i = 0;
while(i < time * 10) { i++; }
}
function testDisplay() {
matrix.clear();
matrix.drawBitmap(smileBmp);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawBitmap(neutralBmp);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawBitmap(frownBmp);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawPixel(0, 0);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawLine(0,0, 7,7);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawRect(0,0, 8,8);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawRect(0,0, 8,8);
matrix.fillRect(2,2, 4,4);
matrix.writeDisplay();
delay(500);
}
testDisplay();
Here's a gif of the above code in action:
Example Code for 16x8 Matrix
var Matrix16x8 = require("espruino-adafruit-led-backpack").Matrix16x8;
var matrix = new Matrix16x8({scl:B6, sda:B7, address:0x70, brightness: 0});
var smileFrownBmp = [
0b00111100, 0b00111100,
0b01000010, 0b01000010,
0b10100101, 0b10100101,
0b10000001, 0b10000001,
0b10100101, 0b10011001,
0b10011001, 0b10100101,
0b01000010, 0b01000010,
0b00111100, 0b00111100
];
matrix.clear();
matrix.drawBitmap(smileFrownBmp);
matrix.writeDisplay();
The functions drawLine
, drawPixel
, drawRect
and fillRect
work the same as for the 8x8 Matrix except you can address up to 16 pixels on the x axis:
matrix.drawLine(3, 3, 15, 7);
Todos - A.K.A. Please Help