Twinkle twinkle little LED

I’m working on a collaborative art project with @Twisted based around the orion constellation. She’s been responsible for the arty side of the project, and I’m covering the technical aspects of it. This is what we’ve got so far:

You’ll notice there are a number of holes on the board, these were laser cut by a company called razorlab, and are currently waiting for me to light them up using LEDs.

Now, because I enjoy biting off more than I can chew, I’ve decided I want to use neopixels (WS2812 RBG LEDs - these are in fact the same as the ones in my UnicornHAT) controlled with an Arduino, to give them a twinkling effect. And I have no idea quite how to achieve this.

My first issue is, what is a twinkle? What are the properties of twinkles, and how can they be replicated using LEDs? I’m thinking that it’s possibly as simple as a having random LEDs light up and fade out - what do you think?

While I’ve been composing this post, I’ve been toying around with the WS2812 library (which has a super simple API, thankfully) and have put this together:

It’s a bit of a mess (I miss Ruby right now), but the basic idea is that it’ll choose a random pixel, which it will quickly fade up to full brightness of 255 (from the default brightness of 55), then slowly fade back out again, before pausing for 200 milliseconds and starting again.

I don’t think this is too bad of an effect, and works OK for the 5 I currently have connected, but if I’m going to be powering 20 of them, I think the effect will be a bit rubbish.

Instead, what I’m interested in doing is having different LEDs fade in and out in an asynchronous fashion - but my brain can’t quite figure out how to achieve that. So, any and all help that can be provided will be appreciated.

Thank you :slight_smile:

Addendum, for an idea of the type of effect I’m after, take a look at this (the effect starts around the 53 second mark):

If it was me…

I’d have ​two​ arrays - one for brightness, one for “twinkle direction”.
0 = unchanging, +1 for getting brighter, -1 for getting dimmer
Each “tick”, you either increase or decrease the brightness of the LED based on its "twinkle direction"
You’ll need to experiment to get the right balance for starting “twinkling” (going from “unchanging” to getting brighter/dimmer, depending on current brightness)
Once an LED reaches max brightness, or is turned off completely, set the “twinkle direction” back to 0

BTW, this is also a pattern for handling sprite jumping in games:

sprite_y = cell_y + (jump_height * max_jump_height) // where jump_height is between 0 and 1

Damn, now I want to start coding games again…

1 Like

Judging by the painting style, I think I owe @Twisted a vote of thanks for ‘The Elephant In The Room’ on the shelf behind me. She’s no trouble and has a better memory than me.

Actually, no :flushed: I did the background painting on the animals, while the outline and lettering were done by my friend Lucy.

Proudly sponsored by Bytemark