FastLEd - Play animations using a MIDI keyboard

Hi everyone,

I would like to control a WS2812B LED strip using a MIDI keyboard.
The idea would be to assign animations to keys of the keyboard. I found some animations on this website:

I managed to play an animation when pressing a key. But I would like the animation to stop if I release the key. And to play another one if press another key.
However, I know there is an issue with interupts.

Do you think this is feasable?

I hope this is clear.

Many thanks.

Yes. It may be enough to rephrase your effects using non-blocking code. Then they run when you want, as long as you want until you decide to give no more attention to the code they use.

See if this makes sense, all I can offer just now from under the umbrella on a tiny screen:

HTH

a7

Make sure you understand this before you start:

Hi @alto777 ,
Thanks for your answer. Makes sense! But I have a qestion..
I understand what you mean by non-blocking code. But animations are usually for loops. So how can I break a loop when I release a key?

Thanks @PieterP . I will try to understand that

Mine aren't. Mine are programmed as functions that, when called, take one step of the animation, if it is time to show the next "frame" of an effect that plays out over time.

Naive code uses for loops and dealy() to do the timing. It's harder to break into that until they are finished. Looping.

If I want an animation to stop, I just don't call the function that steps it along anymore.

It seems like you might not have taken the link I posted, which is to a discussion and code examples that show this idea. The code shows how a function can be written so that calling it every 50 milliseconds (say) will let it publish a new step.

It needs embracing the concepts you will come across if you googled

arduino blink without delay

and

 arduino two things at once

and

 arduino finite state machine

There are some hacks that you could try instead, see

for example. Some are offended by such hacks - I don't argue with success and that approach def works and is easy to see why and wouldn't require a complete change in how you do this kind of thing.

Which way of doing things is still good to,learn at some point, as some,e hacks will on,y get you so far and can be kinda messy.

HTH

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.