I'm using the DuinoWitchery LCD library (https://github.com/duinoWitchery/hd44780) in a PlatformIO Arduino project with CLion.
The following code works if I stick it in main.cpp:
// near top of class...
const PROGMEM uint8_t decimalDigit[10][8] = {
{0x07, 0x05, 0x05, 0x05, 0x07, 0x18, 0x18}, // .0
{0x02, 0x02, 0x02, 0x02, 0x02, 0x18, 0x18}, // .1
{0x07, 0x01, 0x07, 0x04, 0x07, 0x18, 0x18}, // .2
{0x07, 0x01, 0x07, 0x01, 0x07, 0x18, 0x18}, // .3
{0x5, 0x05, 0x07, 0x01, 0x01, 0x18, 0x18}, // .4
{0x07, 0x04, 0x06, 0x01, 0x06, 0x00, 0x18, 0x18}, // .5
{4, 4, 7, 5, 7, 0, 0x18, 0x18}, // .6
{7, 1, 1, 1, 1, 0, 0x18, 0x18}, // .7
{7, 5, 7, 5, 7, 0, 0x18, 0x18}, // .8
{7, 5, 7, 1, 1, 0, 0x18, 0x18}, // .9
};
hd44780_I2Cexp lcd(0x27);
// ... snip ...
void setup() {
for (int x=0; x<8; x++)
lcd.createChar((uint8_t)x, decimalDigit[x]);
// ...snip...
}
... but if I move the code into another class, like:
Renderer.h
class Renderer : BaseRenderer {
public:
virtual void renderTo(hd44780* lcd) override;
// ... snip ...
private:
const PROGMEM uint8_t decimalDigit[10][8] = {
{0x07, 0x05, 0x05, 0x05, 0x07, 0x18, 0x18}, // .0
{0x02, 0x02, 0x02, 0x02, 0x02, 0x18, 0x18}, // .1
{0x07, 0x01, 0x07, 0x04, 0x07, 0x18, 0x18}, // .2
{0x07, 0x01, 0x07, 0x01, 0x07, 0x18, 0x18}, // .3
{0x5, 0x05, 0x07, 0x01, 0x01, 0x18, 0x18}, // .4
{0x07, 0x04, 0x06, 0x01, 0x06, 0x00, 0x18, 0x18}, // .5
{4, 4, 7, 5, 7, 0, 0x18, 0x18}, // .6
{7, 1, 1, 1, 1, 0, 0x18, 0x18}, // .7
{7, 5, 7, 5, 7, 0, 0x18, 0x18}, // .8
{7, 5, 7, 1, 1, 0, 0x18, 0x18}, // .9
};
}
Renderer.cpp
void Renderer::renderTo(hd44780lcd* lcd) {
for (int x=0; x<8; x++)
lcd->createChar((uint8_t)x, decimalDigit[x]);
// ...snip...
}
... the custom characters end up with garbage data.
I think I might be breaking some esoteric rule that governs where you're allowed to put a const PROGMEM uint8_t[]
, and causing the array declared in Renderer.h to end up in SRAM. But I'm not sure how to confirm it OR fix it.
note: the for/next loop to create the chars is just for the sake of illustration & to demonstrate that something that works in main.setup() fails in Renderer.renderTo(). In real life, the sequence of characters getting rendered to the LCD owns one of the 8 custom characters & redefines it as necessary to be the decimal point and tenths value.
static const
?