06-Comet Effect - LED Strip Arduino Tutorial - FastLED Effects - on RGB LED WS2812B and Neopixels

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

It's been awesome seeing you grow your channel dave, massive well done. I remember coming across one of your first videos which were on sound to light which was helpful for my dissertation. I'm still not over the fact that you're the guy behind Windows Pinball and Task Manager 😁

πŸ‘οΈŽ︎ 5 πŸ‘€οΈŽ︎ u/techysec πŸ“…οΈŽ︎ Sep 30 2020 πŸ—«︎ replies

Hi all... this is more targeted at beginners, being it's two pretty basic effects - twinkle and comet - but I figured I'd start at the beginning! Please let me know what you think, and if you have any (constructive) feedback I'm always eager to hear it!

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/daveplreddit πŸ“…οΈŽ︎ Sep 30 2020 πŸ—«︎ replies

I have been following the FastLED posts since back in the Google Groups days. Really like the straight format of your videos, and the explanation of what the code is going to do. When you make tweaks to the code and then see what it does to the light strip, makes learning to code more informative.

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/TeamTermin πŸ“…οΈŽ︎ Oct 01 2020 πŸ—«︎ replies

Thanks for the kind words, folks!

(And I do like to point out whenever Pinball comes up that I just ported It to Windows NT and RISC, etc, and rewrote the asm portions. It already existed as a game from Maxis! Not that you'd have heard of it if I didn't port it for fun, but hey, success has many fathers :-) )

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/daveplreddit πŸ“…οΈŽ︎ Oct 02 2020 πŸ—«︎ replies

Fantastic, just what I needed, thank you πŸ‘πŸ»

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/5htc0der πŸ“…οΈŽ︎ Sep 30 2020 πŸ—«︎ replies

Great idea and great method, Dave. Thanks very much. I'll give it a try.

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/ShauninAlberta πŸ“…οΈŽ︎ Oct 16 2020 πŸ—«︎ replies
Captions
hey i'm dave welcome to my shop i've been seeing stars and comets because those are the led effects that we're going to create today by now you know the drill i code live in the editor as you watch and i explain what the heck is going on and why and i show you the results bugs and all live right here if you're not a programmer it can actually be an interesting introduction to finding out exactly what it is that we do all day and why since the effects are simple enough that anybody can follow along with the logic if you're a new programmer it's a great way to learn particularly the arduino and fast led libraries and even if you're a seasoned pro tinkering with rgb leds can be an entertaining diversion that adds a much needed dose of old-school low-level action to your probably too abstract daily grind because that's blinking lights are always satisfying whereas javascript is not stars is the simpler of the two so we'll start there and then we'll turn the star into a shooting star or a comet or a meteor hey it's art so you can call it what you want but i'll show you how it's done stars and comets coming right up let's get busy the code and the implementation for the twinkle effect is reasonably straightforward all we're going to do is randomly pick one quarter of the leds and light them up in a random color we'll put a small delay in between each one and we'll reset once we've done a quarter of the leds and wipe the slate clean and start over that's all we need to do and it will actually give us a rather convincing christmasy effect let's have it at it the first thing i want to do is include the twinkle.h header file now there is no twinkle.header file yet we're about to write that let's do file new and we'll save it as twinkle.h we'll put a header block at the beginning of it so the first thing we want to do inside the twinkle file is to define a little array of colors that are suitable for rgb christmas lights because we could just randomly pick colors and fully saturate them christmas lights don't come in that many colors there's a standard set red green blue purple yellow or orange i guess more likely so let's make a little array of those colors next we need our draw twinkle which will replace the draw marquee or the fill rainbow function that we initially had i'm going to include the fast led header file from within this header file even though i know it's already included in the main header file just so that we don't get the intellisense warnings that these functions aren't defined the fast led clear function clears the color bits in memory but doesn't actually push them out with actually cycling the square wave on the dado line to actually do the work of clearing them yet it's just going to clear the memory so that when we draw we get a clean blank slate when we're done drawing then we'll actually push the bits out with fast leds show this is the line of code that does the bulk of the work for this effect it selects a random index into the led array and assigns it a random color by picking a random index in a color array and assigning that to whatever color the led is holding this is a bit of a poorly behaved implementation it's a fairly simple and easy understand one so we're going to do it first and then i'll give you a better one but what this does is it's actually going to show the leds wait 200 milliseconds and move on to adding the next led until it's done all 16 and then it's going to reset and return but that's not the most well-behaved thing because even though delay does background work for other threads it doesn't return control to the caller so it can't do anything else unless it spins up other threads i do have one typo here that's going to prevent this from compiling and i have to correct that by changing this fixing the capitalization on g leds and now it should compile and it does so we'll upload it and see what we get absolutely nothing saying again yeah well you know why yeah remember i commented i would draw marquee because we're going to replace it let's actually call draw twinkle okay simple enough let's improve this a bit and then we can tweak it and make it a little more interesting it actually looks better in person than it probably does down here because the dynamic range of the human eye is quite a bit wider than the camera that i'm using so to me they look fairly bright and intense in person even if they're like not that much so in the video so i don't like this implementation of draw twinkle as i said because it doesn't return until it has drawn all 16 leds so let's change that by adding a pass count to keep track of how many leds we've drawn and just reset every 16 and just continually draw every time it'll be actually quite a bit simpler but maybe a little harder conceptually but you'd be the judge let's take a look we'll call this one draw twinkle old and we'll create a new draw twinkle as you likely recall declaring the variable of static means it's valuably preserved from one function call to the next so we will know what the pass count was because we'll increment it each time and it will keep track of it for us so we draw every time we're called and every sixteenth time we're called we reset the strip all right then go confirm that main is still calling the one i intend yes draw twinkle looks right let's upload it see what we get should be about the same and indeed it draws identically but it's a much tidier implementation because it returns control to the caller every time let's tweak it a bit by drawing more leds let's let's draw a number equal to the number of leds that there are and let's take the layout and see what we get so i've changed the number of leds to be the same number that we draw now i clear the leds every time we've drawn 64 leds a number equal to the number of leds and you might wonder well why aren't they all drawn well it's because some are overlapping right they are random each time and that doesn't exclude ones already drawn now that we've done stars it makes sense to do shooting stars as our next step what we're going to do is take a little block of pixels maybe four or five wide and move it back and forth the length of the strip as we're doing that we're going to color fade all of the other pixels on the strip randomly by a little bit each pass through and that will give us a fading tail as we move this bright block of pixels along just like last time our first step will be to include a header file that we then create to describe and define the effect i forgot the draw code last time so i'm going to put the draw in here now that way even if i forget it won't compile we'll create a new file we'll put a header in it there we go there's our skeletal file now we just have to go through and implement it so how am i going to draw it all i'm going to do is i'm going to draw a block of 5 pixels i'm going to move that block back and forth up and down the strip i also want to color cycle the comment as it flies along just a little more visually interesting let me define a few constants up at the top of the function here what we're going to do is run through all the pixels and if a random number generator says randomly fade this pixel this is the amount we're going to fade this pixel by and it's a fraction of 256 because everything in fast led is generally bite based numerator denominator math and so out of 256 how many fractions are we going to fade it by 128 which is half so this value will fade about half the color out when we add that step later on comet size is how many pixels wide the comet is delta hue is how far to step the hue in between each draw call as anticipated we step the hue by that amount each time we come through this function we're also going to update the position of the comet by stepping it in whatever direction the i direction variable points if it's negative one that means it will decrement the position because we're going to add it to the position each time if it's positive one it will increment the position each time and move it to the right or well it depends where your leds are going it will move it positively on your led strip of course the problem is what happens when it hits the right-hand side of the left-hand side it can't overflow and that's the only messy part of this is the test for that case now our comet size is coded to five right now and that means we're going to have to stop five pixels back of the end of the strip because wherever we're drawing from we're going to draw five pixels similarly when we get to the far left hand side of the strip we're going to balance and send the comment back the other way if you're not familiar with what this does it simply multiplies the i direction variable by negative one and puts it back into i direction so it's going to toggle it from 1 to negative 1 to 1 to negative 1 to 1 to negative 1 and so on now let's draw the actual comet at its current position now if we ran this now all it would do is zoom across the screen once and fill the screen because we're never erasing anything remember so what happens if we just erase every frame well let's try that so i've added a fast led clear to the beginning of every frame so that only the comet itself gets drawn and everything else should be blank let's see what that gives us as a start that is our shooting star so far interesting but not all that pretty that's going to make it more compelling well the comet tail fade that's what's going to make all the difference if we just progressively faded each frame i believe that would really just give you sort of a gradient as it flew by we got time let's try it what this code is going to do is going to run through all the leds every pass and dim them now we have to take that erase code out because we don't want it to erase the entire frame we're going to fade them all one step each frame the fast led fade to black by function basically takes any color value you give it and fades it towards black or dims it by the amount you specify out of the 256. i think this will give us a flying gradient we'll see what we actually get not sure why it's winking off like that i'm going to pump my brightness up a bit here to make the effect a little more dimmable and now we're getting somewhere it's a flying gradient and i've got the brightness cranked up now to 255 on my end and i'll try to fix it in post to make everything sort of somewhat visible i'm not sure how the camera is going to handle this one but it's kind of neat but it's just kind of night ridery we really want more of a comet tail effect so let's add an element of randomness to the fades this should fade about every second pixel randomly there that's more satisfying to be clear the random function here is going to pick a value between zero and one because it won't go up to two it'll just do a number below whatever you specify as the max and if that zero or one value is one so half the time it's going to blank out the pixel by 50 and that kind of gives it that sparkly effect in the tail because it doesn't always smooth fade them all now because it's done kind of lumpy lumpy feed i want to make one other change at the end of this episode before we go we're not really using the ola display yet but we are drawing it every frame so let's put a conditional test in there to only draw it every so often and that way we won't waste cycles drawing it like 500 times a second okay so what this is going to do is keep track of the last time that we actually drew the oled display and if it hasn't been 250 milliseconds yet just skip that step if it's been 250 milliseconds or a quarter of a second or more then we'll go and draw it so that should mean we're doing it about four times a second that should also make the comment significantly faster so don't be surprised if it gets a little hectic let's upload it and see what we get yeah a wee bit faster all right let me turn this off for a moment while we go and add a delay back into the code somewhere appropriate so it's not quite this fast but instead of a hard-coded delay in the main loop now it can be entirely up to the effect how fast to be i'm going to delay 40 milliseconds here which means 25 frames a second because 25 times 40. 1000. if i cut the delay in half it should speed it up by a factor of about two and actually double the frames per second as well there we go a double speed comet running at about 46 frames a second 46 to 50 somewhere in there and for our last change let's try making the position a floating point variable so that we can be a little more precise about how far the comet moves each frame rather than one pixel each time because that's going to have the speed of the comet that's also going to make the tail that much shorter so i'm going to change the fade out on the tail to make it fade more slowly i can still use the 1 -1 variable but i'm just going to use it as a multiplier of the comet speed now so it will be half a pixel in either direction as an array indexer we can't use a floating point variable so we need to cast that to an integer not bad but i think i cut the fade out a little too much so let me set the fade back up and give it one last upload i think the next improvement would be to trap multiple comets on the same strip and have them fly back and forth and overlap and color blend that actually might look cool so we'll do that in a future episode if we have time because we're out of time for today i hope you like the effects and the way i presented them i'm not selling anything and i don't have any patreons i'm really just in it for the subs and likes so don't leave me hanging please be sure to leave me one of each before you go join me next time as we add little dose of physics with a set of realistic colored bouncing balls from there it's on to flames and more so if you're not already subscribed this channel is so small you'd certainly miss it in fact even if you are subscribed you likely need to turn on the bell and personal notifications as well that way you'll actually get notified about new episodes thanks for joining me and i'll see you next time out here in dave's garage
Info
Channel: Dave's Garage
Views: 24,773
Rating: 4.983593 out of 5
Keywords: fastled, Led strip effect, fastled tutorial, led effects, neopixel, led strip, arduino tutorial, arduinoΒ tutorial, arduino tutorial led, arduino, tutorial, ws2812b, electronics, led, stem, uno, diy, rgb, rgbled, led strip lights, ws2812b led strip, effects, idea, addressable led, rgb led lights, arduino tutorial for beginners, arduino projects for beginners, rgb lights, led light, arduino project, arduino programming, arduino nano, Rgb led, how to, arduino uno tutorial, fastled patterns
Id: yM5dY7K2KHM
Channel Id: undefined
Length: 18min 35sec (1115 seconds)
Published: Tue Sep 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.