Project: Trying to utilize RGB pixel strips.
Problem: After hours of reading docs and forum posts and trying various permutations I would like to ask for help correcting my code from reading and writing arrays of uint8_t (each value ranges from 0-256) to/from progmem. I have tried to mirror the instructions PROGMEM - Arduino Reference as closely as possible., There has to be some variation because my array's are unsigned ints, instead of strings. The compiler seems to like my array, but the read from memory returns a value different than I stored. For example, the first byte of variable buffer should be decimal 255, but it reads back as decimal 35. Any help greatly appreciated.
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(448, PIN, NEO_GRB + NEO_KHZ800);
prog_uint8_t imagerow1[84] PROGMEM =
{255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
prog_uint8_t imagerow2[84] PROGMEM =
{255,0,0,255,0,0,253,192,191,253,0,2,254,0,0,254,0,0,253,0,2,253,192,191,255,0,0,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,0,0,255,77,77,254,0,0,254,0,2,255,1,3,254,0,0,255,76,79,255,0,0,255,0,0,255,0,0,255,0,0,255,77,77,254,0,0};
prog_uint8_t imagerow3[84] PROGMEM =
{254,0,2,254,0,2,254,0,0,255,77,77,255,0,0,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,0,0,255,76,79,254,0,0,254,0,0,254,0,0,255,1,3,255,77,76,255,0,0,255,0,0,255,0,0,255,0,0,255,78,78,255,1,1,254,0,0,254,0,0,255,1,1,255,78,78};
prog_uint8_t imagerow4[84] PROGMEM =
{255,0,0,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,0,0,253,191,192,254,0,0,254,0,0,255,1,1,253,1,0,253,192,191,255,0,0,255,0,0,255,0,0,255,0,0,255,191,192,253,1,0,254,0,2,254,0,2,253,1,0,255,191,192,255,0,0,255,0,0,255,255,255,255,255,255};
prog_uint8_t imagerow5[84] PROGMEM =
{255,255,255,255,255,255,255,0,0,255,0,0,255,0,0,255,191,191,255,77,77,255,77,75,255,191,191,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,191,191,255,76,77,255,76,77,255,191,191,255,0,0,255,0,0,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,255,0,0};
prog_uint8_t imagerow6[84] PROGMEM =
{255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,0,0,255,255,255,255,255,255,255,255,255,255,255,255,254,46,46,253,0,0,255,1,3,254,0,0,255,1,1,254,0,2};
prog_uint8_t imagerow7[84] PROGMEM =
{254,0,2,255,1,1,255,1,0,254,0,0,255,1,1,254,0,0,255,2,4,253,0,0,254,0,2,255,1,0,254,0,2,254,0,2,255,1,0,255,45,44,255,255,255,255,255,255,255,255,255,255,255,255,255,138,136,253,0,2,254,0,0,253,0,2,254,0,0,254,0,0,254,2,1,253,0,0,255,1,0,254,0,0};
prog_uint8_t imagerow8[84] PROGMEM =
{254,0,2,254,0,0,254,0,2,255,3,0,254,0,2,254,0,0,251,1,2,255,1,0,253,1,0,254,138,138,255,255,255,255,255,255,255,255,255,255,255,255,255,221,222,255,1,3,254,0,0,254,0,0,254,0,0,254,2,0,254,0,0,253,1,0,253,0,0,255,1,1,254,0,0,254,2,1,254,0,0,254,0,2};
PROGMEM const prog_uint8_t *fullimage[] =
{
imagerow1,
imagerow2,
imagerow3,
imagerow4,
imagerow5,
imagerow6,
imagerow7,
imagerow8 };
prog_uchar buffer[84];
void setup() {
Serial.begin(115200);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
testimage(20);
}
//draws a single image on the screen
void testimage(uint8_t wait) {
uint8_t oneChar = 127;
uint16_t oddcolumpixel=0;
uint16_t evencolumpixel=0;
//Don't forget screensize to 24x16!!!
for(uint16_t r=1; r<8; r++) {
oddcolumpixel=16-r;
evencolumpixel=15+r;
memcpy_P(buffer, (uint8_t*)pgm_read_byte(&(fullimage[r-1])), 84);
Serial.print("----Begin Row-"); Serial.print(r); Serial.println("---------");
//Draw a row, two pixels at a time
for(uint16_t j=0; j< 80; ) {
strip.setPixelColor( oddcolumpixel, buffer[j], buffer[j+1], buffer[j+2]);
strip.setPixelColor( evencolumpixel, buffer[j+3], buffer[j+4], buffer[j+5]);
Serial.print(buffer[j],DEC); Serial.print(","); Serial.print(buffer[j+1],DEC); Serial.print(","); Serial.print(buffer[j+2],DEC);Serial.println("");
Serial.print(buffer[j+3],DEC); Serial.print(","); Serial.print(buffer[j+4],DEC); Serial.print(","); Serial.print(buffer[j+5],DEC);Serial.println("");
//get ready to read the next two pixels
oddcolumpixel=oddcolumpixel+32; //map to physical location on head
evencolumpixel=evencolumpixel+32;
j=j+6; //
delay(wait);delay(wait);delay(wait);
}//end row
Serial.println("----End Row----------");
strip.show(); delay(wait);delay(wait);delay(wait);delay(wait);delay(wait);delay(wait);
}//end screen
}//end test image funct