Neopixel strip control without delays

LarryD.

Ok...my fault, so sorry.
I hope this image make it understandable.

I think with the code for it I can customize background color and pixel anim color. Would be nice to have a simple control for the speed of the moving pixel...I think It will be setting the timer value:

if (flag == true && millis() - commonMillis >= ***1000***)

Then I will create state machines to toggle differents effects.

Case 1 : Fade
Case 2 : Moving pixel
Case 3: Rainbow

There are tons of NON-blocking Neopixels solutions out there.. (@Grumpy_Mike 's code comes to mind often)

@Railroader

jfc.. always a rude!?. Nobody FORCES you to respond. If you don't like the question or HOW they asked it... MOVE ON!.. IGNORE IT!! (eye roll) *(cry-baby/victim stance is sad)

1 Like

Yeah you´re right. I have seen many of them. But I would like all the effects share the same logic. Do not have many set ups to run them, cause the code gets crazy.

Adding the back ground colour should be a very easy change you can do.

As for speed add a potentiometer to control the speed, let’s say 100ms to 1000ms, again this should be an easy addition.

Try the two above changes and to see if you can do it.

Yes! while you were replying I made the back ground, now I have to make it just go from left to right and delete right to left.

Than you very much LarryD

Again, this shouldn’t take too long to incorporate.

Have fun !


image

This a much better way of disseminating information.

1 Like

Yes Im pretty sure. Uhmm I tgink I can figure out the fade, mixing the timer with the RGB intesity values.

And I think I can live without the Rainbow.

No you can’t.

That’s the easy way out.

:astonished:

1 Like

I guess I'm not following what you mean by the same 'logic'..

Maybe YOUR project has special needs here?

But in general.. once you have the base code (handling) stuff down.. the only you need to do is add non-blocking animations/functions to build your library of 'special lighting effects' for your project. (All cycled by a button press)

What I mean...is if you pick effects from diferent people, they have their own definition of variables, way of do the timers and so on
So its a little complex to write one code to mix them all.

1 Like

This should ALL be handled in the NON-blocking animation (function) you find/use or create.

There literally dozens of animations.. that ALL use non-blocking approaches... and either just work.. or are easily 'tweaked' to work.

Rainbow, Fades, Theater, Fire, pongs, pixel animations, and the list goes on and on..

Some nice reads?

Animation examples:
https://electromage.com/patterns/

Non-blocking examples/talk:

Good luck!

Thanks for the links. I think I have seen most of them.
The one who has many effects is not trigered by push button, the one with push button has 3 ugly effecta and the multi'tasking is a tutorial that overflow my knowedge.

But many thanks, I will take another look.

Something that I have no said,, is that is for back lighting an alphabet, so I dont want crazy effects

Yes, the sketch the OP is working with does this, kudos to them for at least trying to learn how to do basic programming.

If the OP can learn a few basic techniques, such as BWD and State Machine, they will be able to transfer what they learn to future projects and will become confident in their capabilities.

Saying the above, there is definitely a huge volume out there we can draw from to speed in project development.

2 Likes

That's an option for You too!

Letting someone (you) be rude to a user/poster looking for legit help?

(not an 'option' in my book)

When did You become moderator allowed to criticize using words like You did? Calling me names? No moderator has ever been acting like You did. You deserve being reported.
If my replies are offending You, report me to moderator.
Read the advices for how to communicate here! I just did!

LarryD.
I couldn't make the Fade, not just a simple fade not the fade between colors.
How can I handle 2 timers? one to fill all pixels and the other to fade the values RGB ?

Show us your attempt at doing this.

Always use code tags when attaching sketches to a post.

Here it goes..

added 3 new mState.

const byte maximumState = 7;

case 5 : clear the leds and go on with next mState

    case 5:
      clearLEDs();
      mState=6;
      break;

case 6: FadeIn, when it is finished go on with the next mState

    case 6:
      if (flag == true && millis() - commonMillis >= 5 )
      {
        //restart the TIMER
        commonMillis = millis();

        //green
        tira.setPixelColor(0, 0, greenColor, 0);
        tira.setPixelColor(1, 0, greenColor, 0);
        tira.setPixelColor(2, 0, greenColor, 0);
        tira.setPixelColor(3, 0, greenColor, 0);
        tira.setPixelColor(4, 0, greenColor, 0);
        tira.setPixelColor(5, 0, greenColor, 0);
        tira.setPixelColor(6, 0, greenColor, 0);
        tira.setPixelColor(7, 0, greenColor, 0);
        tira.setPixelColor(8, 0, greenColor, 0);
        tira.setPixelColor(9, 0, greenColor, 0);
        tira.setPixelColor(10, 0, greenColor, 0);
        tira.setPixelColor(11, 0, greenColor, 0);
        tira.setPixelColor(12, 0, greenColor, 0);
        tira.setPixelColor(13, 0, greenColor, 0);
        tira.setPixelColor(14, 0, greenColor, 0);
        tira.show();
        greenColor++;
    }
      if(greenColor>=255){
      mState=7;
      }
      break;

case 7: FadeOut the pixels and loop with case 6

    case 7:
      if (flag == true && millis() - commonMillis >= 5 )
      {
        //restart the TIMER
        commonMillis = millis();

        //green
        tira.setPixelColor(0, 0, greenColor, 0);
        tira.setPixelColor(1, 0, greenColor, 0);
        tira.setPixelColor(2, 0, greenColor, 0);
        tira.setPixelColor(3, 0, greenColor, 0);
        tira.setPixelColor(4, 0, greenColor, 0);
        tira.setPixelColor(5, 0, greenColor, 0);
        tira.setPixelColor(6, 0, greenColor, 0);
        tira.setPixelColor(7, 0, greenColor, 0);
        tira.setPixelColor(8, 0, greenColor, 0);
        tira.setPixelColor(9, 0, greenColor, 0);
        tira.setPixelColor(10, 0, greenColor, 0);
        tira.setPixelColor(11, 0, greenColor, 0);
        tira.setPixelColor(12, 0, greenColor, 0);
        tira.setPixelColor(13, 0, greenColor, 0);
        tira.setPixelColor(14, 0, greenColor, 0);
        tira.show();
        greenColor--;
    }
    if(greenColor<=50){
      mState=6;
    }
    break;

The problem is that if you push the button on mState6 it doesn´t work. Because is on mState 6 and goes to mState 7 again.

On your next break from making progress with you project, take a moment to learn or review how to use for loops.

Reading your code makes my wrists ache!

for (int N = 0; N < 15; N++)
      tira.setPixelColor(N, 0, greenColor, 0);

HTH

a7