Go Down

Topic: Turning a section of adressable RGB LED's on/off (Read 481 times) previous topic - next topic

INTP

There is a
FastLED.clear ();
to wipe all LEDs instead of doing the 'black'. Should've seen that if you read the guide.

Wildviewvermont

#16
Oct 25, 2016, 07:00 pm Last Edit: Oct 25, 2016, 08:20 pm by Wildviewvermont
Thank-you, I was able to change my x value and it now changes colors! :) You guys/gals are the best!

Code: [Select]
x = CRGB::Gold;
You have declared x to be an int, that means it only has 16 bits. This is way fewer bits than a CRGB variable type which is 32 bits long. So x should be a long int.

You code goes on to set all LEDs to gold and then 10mS later it proceeds to set them all to black. You you think this will be at all noticeable?
You then do the same thing in a most turgid way, if you learned how to use arrays all that could be reduced to just 3 extra lines instead of the dozens you have.
No big deal, just write a function to set all the LEDs to black and call that function whenever you need it.
I don't doubt you but I'm curious how you would suggest I reduce my code. I was thinking of making an array of all my arrays. That way I can have one for loop that will go through all of the the arrays. I was also thinking of making an array of colors but will do more reading on arrays. Is that along the lines of what you'd suggest?


I've tested out different delays from 1 second to 10ms and I like the 10ms. It's really "burns" through the array. I might slow it down to 30ms but can always change that later on.


INTP thank-you for the advice. Maybe I've been looking at the wrong Fast Led Guide? I've been using these:

https://github.com/FastLED/FastLED/wiki/Basic-usage

https://github.com/FastLED/FastLED/wiki/Overview

Grumpy_Mike

Quote
but I'm curious how you would suggest I reduce my code.
Basically when ever you find yourself writing the same thing over and over you are doing it wrong. Just write it once in a loop. Yes there will be some magic numbers that differ each time you write it, so you put those numbers into an array and call it up with the incrementing loop index.

Look at this tutorial:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

In your case that code that outputs an array to your LED buffer and plods through each array one at a time can be made into an outer loop and only do the transfer code once.

Go Up