Inspiration
Based on a Python version I wrote a while ago, which was based on a very primitive C++ version written even longer ago. The original versions were made for use in theatrical productions, but I feel it could have personal use.
What it does
The program has a number of animation states that can be swapped between in various cool ways. These animations states are controlled via a command line interface allowing the current animation state to be rapidly (or gradually!) swapped at any time.
How we built it
I stole the LEDs from my high school. I borrowed most of the rest of the components from CSH's RnD. The wiring diagram is simple. A 12V power supply is wired to a standard outlet. The LED's positive and ground terminals are wired accordingly. A second wire is run from ground, and is plugged into a ground pin on the ESP32. A data line is then run from an output pin on the ESP32 into the Din pin on the LED array, allowing for control via Pulse-Width Modulation. Online libraries handle most of the heavy lifting.
Challenges we ran into
First issue: I wanted to be in a team, but couldn't involve anyone. This is a recurring issue where I draw myself into a corner with collaboration. Since I have only one ESP32 and upload cable, I can't exactly collaborate with anyone on my project.
Also, C++ sucks at memory safety. I spent 2 hours wondering why the ESP32 was "panic"ing as a result of some code I wrote to make the LEDs turn on and off smoothly in a "Pulsing" animation. I initially thought that there was some fundamental incompatibility between ESP32 math and cmath, because the pulsing animation used std::cos, but the error persisted when I removed the offending code. A look at the coredump traceback implied that the problem was with the LED controlling library, FastLED. But this didn't add up. Eventually, I realized that I was treating a this pointer as a pointer to an array of RGB structs. I was, effectively, overwriting several hundred bytes of random memory with random values. There was no compiler error, annoyingly. Fixing my typo fixed the program.
Accomplishments that we're proud of
Somehow, nothing exploded and nobody was electrocuted.
I think several of the animations, and some of the tomfoolery you can do with the command line, is fun and entertaining to watch. Some of the animations, particularly "wave" or "pulse", would be fun to have in a larger installation running along the walls of a room.
What we learned
- The memory unsafety of C++. Again. Don't try deleting a pointer twice, the heap will get angry at you.
- How pointers and garbage collection work. A lot of pointers are used, and I need to delete them appropriately. ESP32's aren't capable of handling
std::make_unique, so I had to do all the work myself. - That Python and similar are pampering us with syntax. You can't take the modulus of 2 double values in C++, unlike C#, java, and any other higher-level language; you instead have to do
std::fmod(x, y), which seems ugly. - I don't need caffeine to function. Somehow. Maybe it's the effect of the bright light around me. Maybe it's the fact I've taken 14-hour flights to Japan before.
- How Web servers work. A server waits for a request, and then answers it with either JSON or an HTML file. In this code, the ESP32 sends out a HTML document containing a form. The server then interprets a command sent in the form of a URL, and then redirects the user back to the main page. Frontend is not my forte.
- "Good programming practices". I learned how to do Header files properly, but I feel like having a header file for every single cpp file is a waste in some regard. Also, I keep using .hpp instead of .h, which is also probably an issue.
What's next for LED Control
Joe "OpComm" already drafted me to fix lights.csh.rit.edu. You're welcome, unless I forget to fix it.
The code was written in a very polymorphic manner, and I think that it should be possible to add far more complex functions. I didn't add some of the more advanced animations, mainly because I didn't think they'd look meaningful on the LED array I brought. (eg: "fireworks", required a specially designed LED setup for it.)
Built With
- c++
- esp32
- fastled
Log in or sign up for Devpost to join the conversation.