TM1637 - passing static data

Hi
I am using TM1637 + TM1637Display.h library. All is working ok but I am trying to do some memory usage optimization and here is what I have issue with (lets say I want to display “red”):

Something like this is working:

const uint8_t red[] =  {SEG_E|SEG_G, SEG_A|SEG_F|SEG_G|SEG_E|SEG_D, SEG_B|SEG_C|SEG_D|SEG_E|SEG_G};
...
display.setSegments(red);

Something like this is not working:

display.setSegments({SEG_E|SEG_G, SEG_A|SEG_F|SEG_G|SEG_E|SEG_D, SEG_B|SEG_C|SEG_D|SEG_E|SEG_G});

and is giving me the following error:

TM1637Display.h:62:8: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const uint8_t* {aka const unsigned char*}'

exit status 1
no matching function for call to 'TM1637Display::setSegments(<brace-enclosed initializer list>)'

I wast trying to use or {} brackets in different ways - but still no go…

Finally something like this did compile… but gives me total crap on the display…

display.setSegments((uint8_t)(SEG_E|SEG_G, SEG_A|SEG_F|SEG_G|SEG_E|SEG_D, SEG_B|SEG_C|SEG_D|SEG_E|SEG_G));

Can someone please explain to me how can I pass the data without a need to have it as a variable?

----- edit -----

OK its a bit weird but I found a solution so I will reply to myself:

Since temporary arrays are not allowed to be passed to a function in Arduino we need to use a little trick with the string (as it is an array of chars anyway). Each subsequent char of that string is related to its corresponding place on the display. Also we know that this particular library uses uint8_t type in setSegment() function which in fact is a type of unsigned integer of length 8 bits. So putting all of this together we can find out what string needs to be passed in order to light up the segments that we want:

//      A
//     ---
//  F |   | B
//     -G-
//  E |   | C
//     ---
//      D

 // XGFEDCBA
  0b01010000 // r
  0b01111001 // E
  0b01011110 // d

Now the tricky part :slight_smile:

binary 1010000 = decimal 80 = ASCII "P"
binary 1111001= decimal 121= ASCII "y"
binary 1011110= decimal 80 = ASCII "^"

so to sum up:

display.setSegments("Py^");

will show “rEd” on the display :slight_smile:

To have it more readable for humans we can do:

#define red "Py^"
...
display.setSegments(red);

that uses 12 bytes less of program storage space than:

uint8_t red[] =  {SEG_E|SEG_G, SEG_A|SEG_F|SEG_G|SEG_E|SEG_D, SEG_B|SEG_C|SEG_D|SEG_E|SEG_G};

However const uint8_t (…) at the top of the sketch declaration seems to consume exactly the same amount of memory what I do not fully understand…