indexing - Accessing an item in an array by using a variable as index not working as expected (Arduino) -


i'll start off saying have 0 experience tinkering arduino code, use xc , pics normally.

i'm trying modify bit of code prints characters on oled. problem i'm running when i'm trying value array using variable index.

this array i'm trying data from:

static const uint16_t f_04b036ptdescriptors[95][3] progmem = { {2, 7, 0},          // {1, 7, 2},          // ! {3, 7, 3},          // " etc 

here's how i'm using it:

void lcd_lib_draw_small_stringp(uint8_t x, uint8_t y, const char* pstr) {     uint16_t offset;     uint8_t index;     for(char c = pgm_read_byte(pstr); c; c = pgm_read_byte(++pstr))     {         index = c - ' ';         offset = f_04b036ptdescriptors[index][2]; 

this gives "weird" values offset such -8467 instead of values in 1-300 range stored in array.

i've printed out values of c , index , give values expect don't why doesn't work.

if specify index instead f_04b036ptdescriptors[45][2] works fine , offset gets set value stored in array.

i'm sure it's easy , i'm being moron can't figure out after banging head against wall past 3 hours.

edit: add things i've tried. doing index = 45 works. doing c = 'm' works. giggles tried casting c int (as calculation, index , every combination there of think of. instead of subtracting ' ' subtracted 32 (decimal ascii value space).

still drawing blank on do. i'm thinking might string being stored in flash perhaps?


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -