r/FastLED • u/Fluffy-Wishbone-3497 • Oct 02 '25
Discussion Claude DOES like to code FastLED
https://youtu.be/uf2EEXogPKcI asked Claude to Write some FastLED code because I saw a note about it from Zach on the last update. I didn't even know what Claude was! So, I asked it to "write me c++ code using fastled to display a rotating 3d cube on 120x70 led matrix using ws2812b leds and teensy 4.1 ". Nothing else. I had to add my specific .addLeds for my matrix but it works right out of the box. (I didn't try running it from the command line Yet.) I went on to add options and it did. Flip the screen etc etc. I asked for code to display jpg's from the sd card. It did. Pretty impressive and thorough. I'm having a blast but I feel like I'm cheating or something! I like the way you can keep modifying the code. I wonder how complex you could build something? More fun with FastLED! I'll put the code in the video notes
11
u/ZachVorhies Zach Vorhies Oct 02 '25
6
u/StefanPetrick Oct 02 '25
Suggested next step: Ask Claude to map 2d animations onto the 3 visible sides of the cube.
5
u/StefanPetrick Oct 02 '25
Direct link to the code: https://pastebin.com/YNjC1Z8N
3
u/Marmilicious [Marc Miller] Oct 02 '25
Very cool.
Linked code is currently set to private.
3
u/YetAnotherRobert Oct 03 '25
First, this is impressive for everyone involved, but man, this kind of code is just easier to read and write as c++
Optimizers are aware of c++ things like that vec3d and can take advantage of knowing that interior pointers to x, y, z will never overlap.
Arduino code - at least for any reasonably modern CPU - IS c++. You didn't have to take advantage of every language feature, but a vec2d is a very nice thing to be able to operate on. You can do some of this with c struts, of course.
If you're going to let the machines write it (and, increasingly, we should! Gemini wrote the above from your code and there's very little that I'd have done differently) you might as well let it write code that's easier for both humans and optimizers. As the complexity of the problem grows, the c version gets more complicated faster than a c++ version will.
Just a tip for readers. Just because Arduino code CAN run on 8-bit cpus doesn't mean you have to live with C if the 80s further. Teeny and esp32 can scream with good c++. "But I've heard templates are hard" addLeds{) is already using templates. The template use above is almost invisible. Sure, there's ugly c++, but that possible everywhere.
BTW, is that really 120x70? I'd expect more pixelation.
2
u/StefanPetrick Oct 02 '25
Very nice!
2
u/mindful_stone Oct 03 '25
This is really cool! Thanks for sharing. I started playing around with the code last night and discovered some fun things you can do with it by manipulating a few of the parameters (e.g. the rate and method(s) for incrementing/decrementing angleX, angleY, and angleZ). I'll share more shortly.
P.S., Careful observers such as u/ZachVorhies, u/Marmilicious, u/StefanPetrick and u/sutaburosu will note I'm breaking in a new handle here. Fingers crossed!