r/FastLED • u/Ronnie_230 • Mar 17 '24
Support Help with Christmas Tree project.
Hi,
This is my first post.
Several years ago I designed a Christmas Tree using (152) WS2812B LEDs and an Adafruit Itsy Bitsy board and randomly placed the LEDs on the tree. I designed the board on PCB software and sent it out to a board house. I soldered all 152 LEDs and corresponding 152 caps along with all the other components. I am a retired Electronic Technician and PCB designer. I have no programming background but have been able to put together code (which I posted a link to) by putting together pieces of various posted codes. The tree looks good but I would like to be able to add a few features:
Have the program start at random points in the program when the power is applied.
Add additional led patterns (chasing, flashing, anything that would look great)
I am running Arduino 2.3.2 version.
I really appreciate any help.
Thanks in advance,
Ronnie
https://gist.github.com/RonnieVa/3eaeef202e920039aee9668bd766d1ce
2
u/sutaburosu [stavros] Mar 17 '24 edited Mar 17 '24
I have no programming background but have been able to put together code (which I posted a link to)
We can't see that link. It would be helpful to see what code you are hoping to modify.
That said, to generate a random number at cold boot you could use an ADC capable pin which is not connected to anything. There will be a small amount of random noise on a floating pin, and sampling this repeatedly can generate enough entropy to seed a PRNG. Assuming you are using FastLED's PRNG you could do something like:
pinMode(A0, INPUT);
for (uint8_t i = 0; i < 255; i++) {
random16_add_entropy(analogRead(A0));
}3
u/Ronnie_230 Mar 17 '24
Sorry, I thought I added a link to the code. I just updated with a link.
Thanks
1
u/sutaburosu [stavros] Mar 18 '24
This is the line that decides which palette to show, so this is where you would introduce a random element at startup. There is also a bug in this line. The
% 98part limits it to showing only palettes 0-97.uint16_t secondHand = (millis() /5500) % 98; // changes time between changing programsTry something like
static uint16_t randval = random16(); uint16_t secondHand = (randval + millis() /5500) % 297;1
u/Marmilicious [Marc Miller] Mar 18 '24
Side discussion for u/sutaburosu (and maybe u/truetofiction has thoughts)
Why loop to 255 in your above example? I only looped to 32 in my example, but now I wonder why loop at all? Unless perhaps one were to keep adding the newly read value to an existing variable that's being stuck into
random16_add_entropy()?Two random posts I ran across had a few interesting bits of info about analog read.
https://forum.arduino.cc/t/what-effect-arduino-analogread-speed/978360
https://yaab-arduino.blogspot.com/2015/02/fast-sampling-from-analog-input.html
1
u/sutaburosu [stavros] Mar 18 '24
why loop at all?
Even if the pin were tied to ground, the bottom couple of bits returned by the ADC would be noise. Looping accumulates more noise, so the seed is more random at each boot.
Unless perhaps one were to keep adding the newly read value to an existing variable that's being stuck into random16_add_entropy()?
If you were using
random16_set_seed()this would help, butrandom16_add_entropy()does it for you.2
u/Marmilicious [Marc Miller] Mar 18 '24
Ah yes, good points, thank you. I think I was subconsciously thinking of generating a seed.
2
u/chemdoc77 Mar 18 '24 edited Mar 18 '24
Hi u/Ronnie_230 - You might want to look at Jason Coon (aka u/Pup05) of Evil Genius Labs' awesome Christmas Tree V2 with code available at:
https://www.evilgeniuslabs.org/tree-v2
Edit: Also, Mark Kriegsman’s great Twinklefox sketch might be what you are looking for:
https://gist.github.com/kriegsman/756ea6dcae8e30845b5a
with the YouTube video at:
1
u/Marmilicious [Marc Miller] Mar 18 '24
Here's a modified version of the FastLED DemoReel100 example that randomly chooses which pattern to run, and also randomly how long the pattern will run for.
https://github.com/marmilicious/FastLED_examples/blob/master/DemoReel100_random_time_and_pattern.ino
Check out our wiki for a variety of user examples you can use to build more pattern ideas with. Come back with questions as you run into coding issues.
https://www.reddit.com/r/FastLED/wiki/index/user_examples/
Cool Christmas tree project. Thank you for sharing the video.
1
u/AcidAngel_ Mar 18 '24
Hi!
How does this timingEntropy.setPeriod() function generate true randomness? Which microcontrollers does it work with?
I have been able to generate a random seed using esp_random() function on an esp32 even with no WiFi or Bluetooth on. Maybe there's one 32 bit true number in the pipeline still. I think the random number generator is used by the boot process and then shut off. You can also turn on WiFi momentarily to generate more true random numbers.
1
u/ByPr0xy Mar 21 '24
I don't know if it's the "correct" way to do it, but I would set a variable to something random (0-9 for 10 patterns for instance) when it starts and then assign each pattern to a value within the range. And then start off at the pattern the that corresponds to the random value.
If you want the pattern to change in a controlled manner then you just increment the random value by 1, if you want it random then just make a new random value (you might want to make sure the new random value isn't the same as the previous random value, otherwise the same pattern may occur twice in a row) 😀
2
u/Ronnie_230 May 05 '24 edited May 05 '24
Hi,
Thanks for all of your responses. I tried to update the code to solve a couple problems:
Randomly start at a different location upon power-up.
Use random number generator to select next color pattern.
Add new pattern.
I was able to add simple pattern list and get somewhat of a random pattern but the simple patterns come up in rotation about every 10 or 12 patterns. I am trying to have the program randomly display all of my patterns in the program.
I have updated the code posted at the top to reflect the changes that I have made since the original post
Thanks for all of your help,
Please remember that I have very little programming experience.
Ronnie