Hey all i figured out how to display one colored bitmaps but
how can i achieve multicolored bitmaps? Like this one for example.
I am using a 32x16 LED matrix and an arduino mega
LED Matrix display multicolored bitmaps?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Matrix display multicolored bitmaps?
Adafruit_GFX only supports single-color bitmaps. You would have to write your own bitmap function to draw multicolor bitmaps.
- Disciple
- Posts: 852
- Joined: Tue Jan 06, 2015 8:13 pm
Re: LED Matrix display multicolored bitmaps?
I've done this with the GFX library using NeoPixel matrices. I hope the LED matrix gives similar results.
Your example has six colors. I would encode that as six bitmaps, like this.
These would be written to the matrix in six calls to drawBitmap(), each in its proper color. Each color layer adds to the others in a transparent fashion. With NeoPixels, the whole image can be formed before the show() function updates the LEDs, and glitch-free animations can be created. Do the RGB matrices allow a similar control?
Hallelujah!
Disciple
Your example has six colors. I would encode that as six bitmaps, like this.
These would be written to the matrix in six calls to drawBitmap(), each in its proper color. Each color layer adds to the others in a transparent fashion. With NeoPixels, the whole image can be formed before the show() function updates the LEDs, and glitch-free animations can be created. Do the RGB matrices allow a similar control?
Hallelujah!
Disciple
- opti3000
- Posts: 8
- Joined: Mon Sep 07, 2015 4:40 pm
Re: LED Matrix display multicolored bitmaps?
How do you put them all in a single array? I need to add a extra array line everytime i want to display a new image. The code gets bigger and bigger.
- Disciple
- Posts: 852
- Joined: Tue Jan 06, 2015 8:13 pm
Re: LED Matrix display multicolored bitmaps?
Hi. Sorry for taking so long. Somebody damaged my NeoPixel matrix, and I've been in the repair shop.
Yes, the code tends to swell, but an organized array makes for more compact loops later.
Here's a bitmap made of 16x16 blocks stacked up, 24 of them.
Each stack of six blocks gives the color layers for one image, and four images are joined here. The whole thing goes to the byte array converter, and the byte codes get sorted out into one big array like this one.
This sketch uses the GFX and Adafruit_NeoMatrix libraries to animate the color bitmaps on a NeoPixel matrix. Here it is on a Pro Trinket 5V and my deformed, not-big-enough grid of strips.
For people using the RGB matrices, I don't know how much alike they are, and I'd love to see whether any of these hints work for somebody not using NeoPixels. Let me know if I can help any further.
Hallelujah!
Disciple
Yes, the code tends to swell, but an organized array makes for more compact loops later.
Here's a bitmap made of 16x16 blocks stacked up, 24 of them.
Each stack of six blocks gives the color layers for one image, and four images are joined here. The whole thing goes to the byte array converter, and the byte codes get sorted out into one big array like this one.
Code: Select all
/*
MarioMatrixTest01 - Learn the Adafruit Matrix and GFX libraries by doing.
Animate a 6-color sprite by drawBitmap() operation,
storing all color and animation frames in a single array in PROGMEM.
By Disciple using code from Adafruit.com, and released under their licensing conditions.
*/
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define NEOPIN 12
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 16, NEOPIN, NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);
// Table of 6 colors: Red Blue Tan Brown Gold Black
const uint16_t mColor01[6] = {0x8000, 0x0010, 0xFE0F, 0x3880, 0xFFE0, 0x0000};
// Bitmap of 4 x 6 x 16 x 16 bit sprites:
const PROGMEM uint8_t mario01[4][6][32] = { // 4 sprites, 6 colors per sprite, 32 bytes per color
{{0x0, 0x0, 0x3, 0xe0, 0x7, 0xfc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x7, 0xa0, 0x7, 0xe0, 0x3, 0xe0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x40, 0x0, 0x0, 0x4, 0x0, 0x7, 0xf0, 0xf, 0xf0, 0xe, 0xe0, 0x0, 0x0, 0x0, 0x0},
{0x0, 0x0,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, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0, 0xa, 0x0, 0xb, 0x0, 0xc, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x3, 0x10, 0x3, 0x38, 0x3, 0x70, 0x0, 0x40, 0x0},
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x48, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x20, 0x0, 0x10, 0x0, 0x3c, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}
};
void setup() {
matrix.begin(); // Initialize all Neopixels
matrix.setBrightness(32); // Keep colors dim
}
void loop() {
uint16_t backColor = 0x0400; // Green background
int counter1, spriteNum, pixColor, spriteXpos = 0, spriteYpos = 0;
matrix.fillScreen(backColor); // Clear the BG
// Animate the Mario sprite in a 0-1-2 running cycle
for(counter1 = 0; counter1 < 12; ++counter1) { // Twelve run cycles
for(spriteNum = 0; spriteNum < 3; ++spriteNum) { // times three frames of sprite motion
for(pixColor = 0; pixColor < 6; ++pixColor) // times six color layers per sprite
matrix.drawBitmap(spriteXpos, spriteYpos,
mario01[spriteNum][pixColor], 16, 16, mColor01[pixColor]);
matrix.show();
delay(60);
matrix.fillScreen(backColor); // Clear the BG
}
}
// Make jumping sprite 3 hop up once, and down
for(counter1 = -2; counter1 < 3; ++counter1) { // Five jump steps
for(pixColor = 0; pixColor < 6; ++pixColor) // Six color layers per sprite
matrix.drawBitmap(spriteXpos, spriteYpos - 8 + (counter1 * counter1),
mario01[3][pixColor], 16, 16, mColor01[pixColor]);
matrix.show();
delay(60);
matrix.fillScreen(backColor); // Clear the BG
}
}
For people using the RGB matrices, I don't know how much alike they are, and I'd love to see whether any of these hints work for somebody not using NeoPixels. Let me know if I can help any further.
Hallelujah!
Disciple
- opti3000
- Posts: 8
- Joined: Mon Sep 07, 2015 4:40 pm
Re: LED Matrix display multicolored bitmaps?
Wow that looks s€xy.
Im gonna try it with my LED matrix.
Im gonna try it with my LED matrix.
Please be positive and constructive with your questions and comments.