0

I am using NeoPixel strips, and I want to be able to declare a pointer to them, but not initialize them until the setup function (because they will initialize with certain variables only made available in setup).

For simpler data types, I am just doing:

int totalNumColors = 4; //number of colors user can cycle through`
uint32_t* colorArray = new uint32_t[totalNumColors];
void setup() {
  for (int i=0;i<totalNumColors;i++){
    colorArray[i] = totalColorArray[i];
  }
}

How do I do this for NeoPixel strip intializers? I tried:

Adafruit_NeoPixel* pixels = new Adafruit_Neopixel;`

but I get the error:

expected type-specifier before 'adafruit neopixel'
  • I am trying to wrap my head around using pointers for Neopixels -- I am not a C expert but trying to learn as I go. I went over some documentation (read some sites, watched some YouTube videos) and understand the basics of pointers and I am able to use then in more basic ways. But I am confused how you use pointers when setting up Neopixels. Would you mind sharing some of your code so I can get an idea how the Neopixels are setup and how you are using them? I would greatly appreciate it. David – David Warren Oct 13 at 14:54
1

You can assign the pointer to NULL, and in the setup function give it a value. Note you have to add () for the arguments, even if there are none like in this case. Also you have to include the library (but probably you did but not added in your question).

#include "Adafruit_NeoPixel.h"

Adafruit_NeoPixel* pixels = NULL;

void setup() 
{
  pixels = new Adafruit_NeoPixel();
}
| improve this answer | |
  • 1
    I did include the library, but thanks, yes - this is exactly what I was looking to do. – mheavers Jan 22 at 23:04
  • Good luck with your project. – Michel Keijzers Jan 22 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.