Skip to content
Michael Miller edited this page Apr 12, 2016 · 1 revision

I want to have my sketch do other important work like networking; how do I use your library with other features?

There is little in my library that will stop you from using its features along with other libraries. Make sure the PIN that is being used is not conflicting and that the other libraries refrains from blocking the loop() for long periods of time and it should just work.

Here are a few tips to follow:

1) Outside of setup() and loop(), do not call NeoPixelBus.Show() nor NeoPixelAnimator.UpdateAnimations().

Your loop() should look something like this.

void loop() {
  // any other code that needs to be run often
  // avoid calls to delay() as it will slow down your NeoPixel refresh rate

  animator.UpdateAnimations(); // if you don't have animations in your sketch, you can omit this line
  strip.Show();
}

These two functions are smart and will only do work if they need to as they were meant to be called often.

2) Use animations for all color changes outside of setup().

Another way to say this is to put all SetPixelColor(), ClearTo(), and Rotate*() only inside an animation update callback and call StartAnimation() and StopAnimation() to get changes applied.
Often you want to react and make changes in a callback, like from networking. These callbacks need you quickly do something and then return. Calling StartAnimation() is very quick; and the processing of the animation happens latter. Even clearing all the pixels to black takes more time than you should use within a networking callback.

3) Refrain from using delay() or similar time eating calls.

These sorts of functions just eat time without using those CPU cycles for other work. While it might seem to make your code easier to read, it leads to very sloppy coding styles that will quickly block you from doing more advanced things with your sketch.
If you require timing related code, and they are not NeoPixelAnimations, please review my other library, Task, that helps you break your code into smaller pieces and run them in a similar way that the animations are run.

Clone this wiki locally