1

したがって、画像のバイト配列を外部eeprom(c24LC16B)に入れ、Adafruit gfxライブラリのdrawBitmap()関数を使用して、Nokia 3310 LCD(Adafruit PCD8544ライブラリを使用)に描画しようとしています。しかし問題は、drawBitmap() が静的バイト PROGMEM 配列しか使用できないことです。が悪いので、img 配列を eeprom からバッファ (バイト buf[504]{}; ) に読み取ってから、ディスプレイに描画する必要があります。

これをAdafruit_GFX.ccpに追加するなど、オンラインで見つけたいくつかの変更を試みました。

void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
                  uint8_t *bitmap, int16_t w, int16_t h,
                  uint16_t color) {

  int16_t i, j, byteWidth = (w + 7) / 8;

  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {
      if(bitRead(bitmap[j], 7-i))  
        drawPixel(x+i, y+j, color);
    }
  }
}

それでもゴミしか表示されませんでした

では、なぜ PROGMEM と通常の配列についてそれほど大きな問題があるのでしょうか? PROGMEM からのバイトと SRAM からのバイトは同じではありませんか? また、私の文法について申し訳ありません。

4

1 に答える 1

2

やったよ !私がしなければならないのは、自分の関数を書くことだけでした! =D

これを Adafruit_GFX.ccp に追加するだけです

void Adafruit_GFX::drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bg, byte bitmap[], int mapSize) {
  int pozX = pozXi;
  int pozY = pozYi;

  for (int x = 0; x < mapSize; x++) {
    for (byte y = 0; y < 8; y++) {
      byte dummy = bitmap[x] << y;
      if (dummy >= 128) {
        drawPixel(pozX, pozY, color);
      }
      else {
        drawPixel(pozX, pozY, bg);
      }
      pozX++;
      if (pozX == w + pozXi) {
        pozX = pozXi;
        pozY++;
      }
    }
  }
}

void Adafruit_GFX::drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bitmap[], int mapSize) {
  int pozX = pozXi;
  int pozY = pozYi;

  for (int x = 0; x < mapSize; x++) {
    for (byte y = 0; y < 8; y++) {
      byte dummy = bitmap[x] << y;
      if (dummy >= 128) {
        drawPixel(pozX, pozY, color);
      }
      pozX++;
      if (pozX == w + pozXi) {
        pozX = pozXi;
        pozY++;
      }
    }
  }
}

これはAdafruit_GFX.h用です

drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bg, byte bitmap[], int mapSize),
drawRamBitmap(int pozXi, int pozYi, int h, int w, byte color, byte bitmap[], int mapSize),

利用方法:

drawRambitmap(x,y,h,w,color,byte_array_of_img, size_of_array);

また

drawRambitmap(x,y,h,w,color,background_color,byte_array_of_img, size_of_array);
于 2015-09-07T10:12:16.347 に答える