C++ Arduino图标库
我正在进行Arduino项目,我想在NeoMatrix 8x8面板上显示图标C++ Arduino图标库,c++,arduino,C++,Arduino,我正在进行Arduino项目,我想在NeoMatrix 8x8面板上显示图标 最初,我走了一条依赖继承的方向,请求在我被建议去另一条路线的地方输入一些输入,并在其他地方问我问题,它对C++的影响比ARDUIO还要多。 他们建议我将图标存储在PROGMEM中,让程序从中构建图标,而不是依赖于继承 我尽我所能尝试了这种方法,但我并不自在,所以我想进一步了解 其想法是使用一个字节数组来组成一个8x8图标 值为0-2,每个值表示RGB结构数组中的颜色集 据我所知,PROGMEM中存储的字节数组是作为
最初,我走了一条依赖继承的方向,请求在我被建议去另一条路线的地方输入一些输入,并在其他地方问我问题,它对C++的影响比ARDUIO还要多。 他们建议我将图标存储在PROGMEM中,让程序从中构建图标,而不是依赖于继承
我尽我所能尝试了这种方法,但我并不自在,所以我想进一步了解- 其想法是使用一个字节数组来组成一个8x8图标
- 值为0-2,每个值表示RGB结构数组中的颜色集
typedef struct {
byte r;
byte g;
byte b;
} RGB;
const byte PROGMEM WifiIcon[8][8] = {
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 2, 2, 2, 2, 1, 1},
{1, 2, 1, 1, 1, 1, 2, 1},
{2, 1, 2, 2, 2, 2, 1, 2},
{1, 2, 1, 1, 1, 1, 2, 1},
{1, 1, 1, 2, 2, 1, 1, 1},
{1, 1, 2, 1, 1, 2, 1, 1},
{0, 0, 0, 1, 1, 0, 0, 0}
};
const RGB WifiIconColors[3] = {
{0, 0, 0},
{0, 0, 0},
{0, 200, 61}
};
ESP8266Neomatrix.ino
#include "header.h"
void printIcon(int startPosition, const byte (&icon)[8][8], const RGB (&colors)[3]){
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
byte currentPixel = pgm_read_byte(&icon[i][j]);
const RGB currentColor = colors[currentPixel];
byte red = currentColor.r;
byte green = currentColor.g;
byte blue = currentColor.b;
matrix.setPixelColor(startPosition++, red, green, blue);
}
}
}
#包括“header.h”
无效打印图标(int起始位置、常量字节和图标)[8][8],常量RGB和颜色)[3]){
对于(int i=0;i<8;i++){
对于(int j=0;j<8;j++){
字节currentPixel=pgm_read_字节(&icon[i][j]);
const RGB currentColor=颜色[当前像素];
字节红色=currentColor.r;
字节绿色=currentColor.g;
字节蓝色=currentColor.b;
setPixelColor(startPosition++、红色、绿色、蓝色);
}
}
}
如果您希望RGB数据驻留在PROGMEM中,因为它不是由
pgm_read_XXX
函数处理的本机类型,只需使用以下命令读取:
如果出现崩溃,那么您读取的
currentPixel
的值可能有问题。谢谢您,它可以工作。我得好好读一读,为什么要投否决票?我看不出这项研究怎么还不够。
RGB currentColor;
memcpy_P(¤tColor, colors + currentPixel, sizeof(RGB));