That is a neat trick with the string! I’ll definately use it in future projects - especially because one can do this sort of thing with such a string constant:
byte octet = (byte)stringconstant[i]
and
foreach(char ch in stringconstant)
{
byte octet = (byte)ch;
}
That is a lot like a “const byte[]” and will be very useful for things like packet headers in comms packets or larg(ish) byte arrays that should rather live in flash than RAM.
I digress…
I’ve tried the following two techniques and both also work:
This one stores the bitmaps in program space and takes a slight performance hit for filling the byte array. The GC can collect these easily so RAM footprint is low.
private byte[] GetCharBitmap(char ch)
{
switch (ch)
{
case '0': return new byte[5] { 0x3e, 0x51, 0x49, 0x45, 0x3e };
case '1': return new byte[5] { 0x00, 0x42, 0x7f, 0x40, 0x00 };
case '2': return new byte[5] { 0x42, 0x61, 0x51, 0x49, 0x46 };
case '3': return new byte[5] { 0x21, 0x41, 0x45, 0x4b, 0x31 };
case '4': return new byte[5] { 0x18, 0x14, 0x12, 0x7f, 0x10 };
case '5': return new byte[5] { 0x27, 0x45, 0x45, 0x45, 0x39 };
case '6': return new byte[5] { 0x3c, 0x4a, 0x49, 0x49, 0x30 };
case '7': return new byte[5] { 0x01, 0x71, 0x09, 0x05, 0x03 };
case '8': return new byte[5] { 0x36, 0x49, 0x49, 0x49, 0x36 };
case '9': return new byte[5] { 0x06, 0x49, 0x49, 0x29, 0x1e };
default: return new byte[5] {0xff,0xff,0xff,0xff,0xff};
}
}
This one is more efficient, but is limited to 8 bytes to describe the font. It is very easy to generate the code with a font generator.
private UInt64 GetCharBitmap(char ch)
{
switch (ch)
{
case '0': return 0x3e5149453e;
case '1': return 0x00427f4000;
case '2': return 0x4261514946;
case '3': return 0x2141454b31;
case '4': return 0x1814127f10;
case '5': return 0x2745454539;
case '6': return 0x3c4a494930;
case '7': return 0x0171090503;
case '8': return 0x3649494936;
case '9': return 0x064949291e;
default: return 0xFFFFFFFFFF;
}
}
I then just shift the bytes out to the display.
My next task is to test the total memory footprint and performance of each and see which one wins!
Thanks for all the help so far.