Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
Ehm ... what is your starting point? Did you try any code already? I'm not quite sure where you're getting stuck ...
Both NeoPixel and FastLED (recommended) use an array to hold all LED colors.
So if you fill the entire array with black, all leds will become black once you call the "show" command.
If you only set LED #7 to green, and you call the show command again, then all LEDs will still be black, except for #7 which will be green. If you after that set only LED #8 to red, and you call the show command again, then all LEDs will still be black, except for #7 which will be green and #8 will be red.
Point being: a LED color will only change if you set that particular LED to a color, AND you call the show function (which updates all LEDs).
I kept working with my function and now I got all LEDs I need to light, but I still stuck on blink function. Your hit that all LEDs are stored as array was good for me.
I created an array with the LEDs I need to light.
int ledsUsed[25] = {0,1,2,3,4,11,12,13,14,15,22,23,24,25,26,33,34,35,36,37,44,45,46,47,48};
then I modified my funtion and set the leds to green depends on my array size and specified leds there:
void test2(uint32_t color, unsigned long duration, uint32_t off, int ledsUsed[] , int ledsUsedSize) {
for (int i=0; i<ledsUsedSize; i++){
strip.setPixelColor(ledsUsed[i], green);
strip.show();
}
}
Funtion call:
test2(green, 1000, off, ledsUsed, 25);
Now I need to make the first 5 leds show up, 1 second later the secont 5 and so on. How to to that? do I have to create for each block of 5 leds its own array? Or maybe I can use for loop to go on, because the space between the 5 light leds is always 7 leds that are off.
Actually, the idea was this: FastLED (and NeoPixel) use an array to represent all LEDs. I assume you're already doing this, so I'm kind-a adding this explanation for others that may be reading this.
I'm assuming FastLED here, even though you seem to be using NeoPixel. FastLED is (in my opinion) a much better, faster and more mature LED library (documentation: here and here).
So for a strip of 60 LEDs, connected to pin 5, using FastLED, we start with something like this:
The array is called "leds" and each element in the array are of the type "CRGB" (a color). The function call in the loop initializes the strip, so FastLED knows how to work with it.
Next we set a color with one of these methods - where we set element "i" from the CRGB array called "leds":
// set individual R, G, and B fields, the classic way:
leds[i].r = 255;
leds[i].g = 0;
leds[i].b = 0;
// set RGB from a single (hex) color code
leds[i] = 0xFF0000; // red
// set RGB from a standard named web/HTML color code
leds[i] = CRGB::Red;
// set RGB using 'setRGB' and three values at once
leds[i].setRGB( 255, 0, 0);
// copy RGB color from another led (v2)
leds[i] = leds[j];
Now with that we have only set the color, but have not yet asked FastLED to apply the change. This is done with the show() function:
FastLED.show();
In the next reply I'll look at how to change the LEDs.
It is a little challenging (and I would do some experimenting). We should probably first look at what exactly happens in your animation. I've just uploaded your animation as a video in your initial post.
So when looking at your animation, we see these steps:
Make LEDs 0, 1, 2, 3, 4 fade to green
While LEDs 0, 1, 2, 3, 4 stay green, Make LEDs 9, 10, 11, 12, 13 fade to green.
While LEDs 9, 10, 11, 12, 13 stay green, Make LEDs 16, 17, 18, 19, 20 fade to green, Make LEDs 0, 1, 2, 3, 4 fade to OFF
While LEDs 16, 17, 18, 19, 20 stay green, Make LEDs 25, 26, 27, 28, 29 fade to green, Make LEDs 9, 10, 11, 12, 13 fade to OFF
etc
So with each step we kind-a see this:
- "block" X fades to green (where X is the current block or column) - "block" X-2 fades to black (- the rest ("block" X-1) remains untouched, either green or black, but we do not need to do anything with that)
Seems we have 6 "blocks", each of 5 LEDs, and the blocks start at LEDs 0, 9, 16, 25, 32, 41. (alternating +9 (5+4) and +7 (5+2))
Block X, X-1 and X-2 can potentially be invisible. For example: - when X = 1 then we see only Block 1, since X-1 and X-2 are negative, or - when X=8 (passing the 6th block), then blocks X and X-1 are invisible.
I hope that made sense - took me a minute to figure that one out as well 😜
So ideally I'd like to have a function that draws the 2 (3) steps we just found, based on the position. Meaning: in the list above we have items 1, 2, 3, 4, etc and I'd like to pass that number to a function so the proper leds will be drawn or faded.
Something like this, so we can say what column we want and what the target color should be (so we can use this later for another color as well);
In this function we want to do the steps we found:
- Draw the column (X) if visible - Fade a column if visible (X-2)
Since you do fade to green and fade to black at the same time, we should actually do these changes simultaneously.
So a for-loop should fade one column in (X = ColumnXStart) and one column out (X-2 = ColumnX2Start) at the same time. We will need to calculate the starting points of X and X-2 (I know the calculation looks a little funny - below I'll post code that shows the calculation works)
ColumnXStart = (int)*( (Column+1)/2 )*9 + (int)*( Column/2 )*7;
ColumnX2Start = (int)(( (Column-2) +1)/2)*9 + (int)( (Column-2) /2)*7;
for(int i=0; i<=5; i++) {
if( (ColumnXStart>=0) && ( (ColumnXStart+i)<NUM_LEDS) ) {
leds[ColumnXStart+i] = targetColor / (5-i); // something to scale up brightness - probably not the best method
}
if( (ColumnX2Start>=0) && ( (ColumnX2Start+i)<NUM_LEDS) ) {
leds[ColumnX2Start+i] = leds[ColumnX2Start+i].fadeToBlackBy(25); // experiment with this number (25)
}
FastLed.show():
}
Hope this gibberish gets you started ... 😉 Note that calling the function, probably should go from zero to 8 (for 6 columns).
MalwareBytes Probably one of the best tools to prevent and remove all kinds of malware and viruses on Windows and MacOS X.
SpeedTest.net Test the speed of your Internet connection (requires Flash!!!)
Ulvenhout.com My home town ... Ulvenhout in the Netherlands (Noord Brabant)
GTMetrix Awesome tool to analyze the speed of your website!
Microsoft PowerToys for Windows 10 Back in the day (Windows 98/XP era) we had PowerToys - Microsoft released them again for Windows 10 (free)
IINA VideoPlayer One of the best media players for MacOS X - it's free and a great alternative for, and more stable than, VLC.
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).