I am new to this forum and adafruit products. I am trying to draw a bitmap from PROGMEM. My 128x128 16 bit bmp has three strokes: RED BLUE and GREEN. My code works fine and I can see the strokes. BLUE stroke comes perfectly. However the Green stroke comes as RED and the RED as black. I tried to modify the code several times but I am not able to get rid of this issue. I will post my code below. The hex values are generated usinf LCD image converter for bitmap PROGMEM.
NOTE: when the same image is read from the SD card it outputs perfectly without any of the above stated issue.
Thanks,
Vishnu
Code: Select all
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <SD.h>
#include <SPI.h>
// If we are using the hardware SPI interface, these are the pins (for future ref)
#define sclk 13
#define mosi 11
#define cs 5
#define rst 6
#define dc 4
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x7E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// to draw images from the SD card, we will share the hardware SPI interface
Adafruit_SSD1351 tft = Adafruit_SSD1351(cs, dc, rst);
static prog_char PROGMEM lily128[]= { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf800, 0xf800, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, .............(16384 elements)
};
void setup() {
Serial.begin(9600);
tft.begin();
drawBitmap(lily128,128,128,0,0);
}
void loop() {
}
void drawBitmap( prog_char *bitmap, int width, int height, int at_x, int at_y)
{
uint16_t r=0,g=0,b=0,k;
k=0;
uint16_t pixel;
for (int i=0; i<height; i++)
{
for (int j=0; j<width; j++)
{k=(j*width)+i;
pixel = pgm_read_word(bitmap);
bitmap++;
r = (unsigned char)((pixel & RED));
g = ((pixel & GREEN));
b = ((pixel & BLUE));
tft.drawPixel(at_x+j,at_y+i,tft.Color565(r,g,b));
}
}
}