AaronLiddiment / LEDText

FastLED Flexible Text Message Class requires LEDMatrix Class
89 stars 32 forks source link

Add variables to scrolling or static text #17

Open keukenrol opened 4 years ago

keukenrol commented 4 years ago

Hi

is it possible to display the value of a variable? Furthermore, is there a method to show it as static text? The text string is a constant at the moment, so I suppose this is not possible?

For example:

const unsigned char TxtDemo[] = {" GS: ", %d}; Behind GS i would like to show the value I send to the microcontroller. Something using the analogy of how you show an integer in C. @AaronLiddiment

karlzre commented 3 years ago

Hi,

I'm also interrested to find out how we can print a variable value. I would like to use you library to make a Instagram counter . thx

fadesibert commented 2 years ago

I was able to solve this, accidentally learning more C++ than I expected... (with apologies to real developers)...

basically, take your string input, and convert it to an array of unsigned char (the byte variables used by LEDText).

The initial initialization with a scroll method may actually be unnecessary, but it works.

So String -> char[] using strncpy (which handles potential overflows as the length of the string may vary at runtime) convert signed char[] -> const unsigned char[] pass to LEDText

void displayScrollingMessage(String message)
{
  char msg_c[254];
  unsigned char msg_uc[256] = {EFFECT_SCROLL_LEFT};                             // Prepare for an array of unsigned char

  strncpy(msg_c, message.c_str(), 254);

  std::copy(msg_c+2, msg_c + 256, msg_uc);                                      // Copy the char array to unsigned char, correctly converting
  const unsigned char * TextMessage[] = { msg_uc };                              // Compose the message String into an LED Text Message
  ScrollingMsg.SetText(msg_uc, 255);                                            // Finally, pass to ScrollingMsg
...
}
fadesibert commented 2 years ago

See this repo for an example: https://github.com/fadesibert/arduino_esp32_scroller