All too often I have found myself wanting to experiment with different patterns on NeoPixel strips, yet testing takes a very long time. Each change requires recompiling and reuploading the program to the board. Additionally, adding more pixels uses up more valuable desk space. This is why I got the idea to create a simple program in Python that allows users to port over their code and make changes with very little change, as well as being able to add up to 1,000 NeoPixels easily.
You can find the GitHub repository here.
Basic LogicAt its core, the Python program has a class that contains the main functions for the NeoPixels. These include the constructor, begin, show, and setPixelColor. Each pixel is also its own object which gets stored in a list. The pixel object stores its color and position in the chain. The next class handles the GUI, which draws the pixels and lights to a window onscreen.
Even though the actual NeoPixel library uses C++ and the emulator uses Python, I still wanted the syntax to be as similar as possible. I have ported most functions from the library to the emulator, which means that the two can be copy/pasted back and forth with relative ease. This allows for simple changes to be made, tested, and merged back with the C++ program.
I decided to use the Pyglet Python library to handle the GUI. It allows for sprites to be easily drawn and changed, unlike PyGame.
To begin, it draws the images of the WS2812b LEDs in rows of up to 50 NeoPixels each.
Next, simple black circles get placed over each LED. Each time pixels.show() is called, the window gets rendered to reflect any changes that were made. Brightness is represented as opacity, and the circles are simply recolored to the specified hue and saturation.
One drawback to the Adafruit NeoPixel library is that many effects have to be created by the programmer and are not built-in. I decided to add a class that contains several different LED effects, and all that is needed is passing in the neopixel object and delay/color parameters when necessary. Some effects include rainbow, ranbowCycle, and colorWipe.
Using the emulator is easy! Type out the code that would be used to light up the LEDs on a real neopixel strip, just make sure to use Python syntax. When the program is run, the GUI shows what the LEDs would look like on a physical strip, and after the function completes, the GUI and program exit.
In the future, I would like to add the ability to simulate entire NeoPixel matrices and even make a library like Adafruit GFX to handle the display. But for now, this emulator works fine for viewing and changing animations on an LED strip.
Comments