mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-07 12:54:26 +02:00
Created FAQ (markdown)
22
FAQ.md
Normal file
22
FAQ.md
Normal file
@@ -0,0 +1,22 @@
|
||||
## I wish to dynamically set the number pixels, other libraries expose a method to change the number of pixels like updateLength() or setPixelCount().
|
||||
The key word here is dynamic. The best practice when dealing with key feature change is to dynamical create the object and recreate it when things change. It will often lead to smaller program code size even though you may have to type more. See the following snippet of code as an example of how to do this.
|
||||
```
|
||||
// declare your object as dynamic, a pointer to it, the *
|
||||
// a good practice is to set it NULL
|
||||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>* Strip = NULL;
|
||||
|
||||
// inside setup, allocate your default, or maybe you don't do this and just wait for outside influence
|
||||
Strip = new NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>(PixelCount, Pin); // this dynamically creates one
|
||||
Strip->Begin(); // since its a dynamic object pointer, you need to use -> instead of just a period
|
||||
|
||||
// latter in your code, due to some outside influence, you need to change the pixel count
|
||||
if (Strip != NULL) {
|
||||
delete Strip; // delete the previous dynamically created strip
|
||||
}
|
||||
Strip = new NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod>(newCount, Pin); // and recreate with new count
|
||||
Strip->Begin();
|
||||
|
||||
// other parts of your code, you set the colors, and show
|
||||
Strip->SetPixelColor(0, RgbColor(0));
|
||||
Strip->Show();
|
||||
```
|
Reference in New Issue
Block a user