Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Arduino图标库_C++_Arduino - Fatal编程技术网

C++ Arduino图标库

C++ Arduino图标库,c++,arduino,C++,Arduino,我正在进行Arduino项目,我想在NeoMatrix 8x8面板上显示图标 最初,我走了一条依赖继承的方向,请求在我被建议去另一条路线的地方输入一些输入,并在其他地方问我问题,它对C++的影响比ARDUIO还要多。 他们建议我将图标存储在PROGMEM中,让程序从中构建图标,而不是依赖于继承 我尽我所能尝试了这种方法,但我并不自在,所以我想进一步了解 其想法是使用一个字节数组来组成一个8x8图标 值为0-2,每个值表示RGB结构数组中的颜色集 据我所知,PROGMEM中存储的字节数组是作为

我正在进行Arduino项目,我想在NeoMatrix 8x8面板上显示图标

最初,我走了一条依赖继承的方向,请求在我被建议去另一条路线的地方输入一些输入,并在其他地方问我问题,它对C++的影响比ARDUIO还要多。 他们建议我将图标存储在PROGMEM中,让程序从中构建图标,而不是依赖于继承

我尽我所能尝试了这种方法,但我并不自在,所以我想进一步了解

  • 其想法是使用一个字节数组来组成一个8x8图标
  • 值为0-2,每个值表示RGB结构数组中的颜色集
据我所知,PROGMEM中存储的字节数组是作为指针读取的,需要使用ppm_read_byte进行访问

我不确定如何处理RGB结构。当我试图从PROGMEM读取它时,它会导致我的程序崩溃。所以我从PROGMEM中删除了它,图标显示正确。我的字节数组是PROGMEM格式的,但不是颜色

我意识到我对需要处理的指针严重缺乏了解…

另外,这个想法是要有一个图标集合,所以我应该将所有图标(字节数组和颜色)存储在头文件中吗?这不会使它膨胀吗

提前感谢您对此的见解

标题.h

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(&currentColor, colors + currentPixel, sizeof(RGB));