Picture

Mapping text on the leds with C++

How do I show vector based text on a pixel based led strip?

  • # Mapping
  • # Text
  • # C++
Picture

In a previous blog, I mapped letters in my virual div tree. The next step is to map these letters on the real leds.

But first the message must be sent from the browser to the database to the arduino, this I have already explained in a previous blog. I haven't decided yet under which form I will send these messages. There are two possibilities:

1) I store the message as a string in the realtime database, I split this string into a char array in C++, loop over this array en write the logic so that the right leds are on per letter. The advantage of this is that I make more effienct use of the database and do not store, send and retrieve a lot of unnecessary characters. A disadvantage is that I then have to do all the mapping logic in C++ and put it on the Arduino. In C++ it is less convenient to work with arrays and the board has only a limited storage space (already 71% is used)

2) I write al the logic in JavaScipt so that I have an array of all the burning leds per message. Then store this big array in the database and read it in C++. The disadvantage here is that I have to store and retrieve a lot of data from the database. I would also challenge myself less in C++

I went for option 1. Working with arrays in Arduino was the tricky part here, especially wilt multi dimentional arrays since you need to know in advance how many elements are going to be in the array and I didn't know that. So in this case I picked 100, because the longest letter array was about 100 items. When an array is smaller than 100 items, it puts a 0 instead. But I can filter that out later. This is how my 2D array for the alphabet looked like:

Picture

So when the Arduino detects a new incoming message, it splits that message, puts it in an array. After that is looks for the ASCII code for that letter (that was a tip from Simon). The ASCII code for A is 65, B = 66, C=67,... Then I do that number minus 65. What does that leave me with? The index of the letter in the above 2D array. Than I just need a loop in a loop to diplay every led per letter, per word.

Picture

(I know that showing a picture of code instead of copy pasting it the most evil thing you can do, but you can find all the code on my github respository)

This is the result:

In this test, letters are formed gradually. I could also show them faster right away, but I thought this effect was cool.