From 64fb3e7909ab20cb104f064c1268423d4713b066 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 26 Feb 2016 01:09:08 -0800 Subject: [PATCH] Created FAQ (markdown) --- FAQ.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 FAQ.md diff --git a/FAQ.md b/FAQ.md new file mode 100644 index 0000000..c3b2e66 --- /dev/null +++ b/FAQ.md @@ -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* Strip = NULL; + +// inside setup, allocate your default, or maybe you don't do this and just wait for outside influence + Strip = new NeoPixelBus(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(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(); +``` \ No newline at end of file