While cleaning up my drawer with my Secret Stash of Ingredients, I stumbled into my beloved NeoMatrix 64 pixel LED board. While this board is an awesome toy for light effects, it could use some added features, like the displaying text. Reason enough to write a NeoMatrix extension for the Adafruit GFX Library.
Now, although that might sound very confident, I wasn’t very experienced in writing my own libraries. But as I’ve learned from many other programming languages, the best way to do it, is to take an existing piece of code, and learn from it.
So after half an hour of fiddling around, checking the compiler errors, and some minor cursing every now and then, my own NeoMatrix library started to look promising.
There was one issue left to be solved: converting the Adafruit GFX colors to the NeoPixel color values. Is wasn’t easy, because the Adafruit GFX library uses Gamma corrected values.
Time to fire up my savior in difficult times: Google. And soon enough, I ran into a library that includes the same color conversion … The Adafruit NeoMatrix Library. But then I read the library description:
Adafruit GFX-compatible library for NeoPixel matrices and grids. Controls single and tiled NeoPixel displays such as the Adafruit NeoPixel Shield or grids assembled from Adafruit 60 LED/meter Digital LED strip. Requires Adafruit NeoPixel and Adafruit GFX libraries.
Wait a minute!? This is exactly what I was trying to accomplish! Not only is this library a fully worked out piece of code, but it’s also written by Adafruit: the creators of the NeoMatrix boards. Sigh …
Firing up the example included in the library’s repository demonstrated it can do exactly what I want. A shiny bright Hello World!
So not only did I learn how to write my own libraries today, but more important, I learnt I need to Google before I start reinventing the wheel. Maybe I should start a peer group “Anonymous Reinventors of The Wheel”. Will you join me?