I have small problem on defining and referencing an adafruit_Neopixel object that i want to put in a variable inside a struct here is the defenition of the struct,
struct ledPanels {
int GPIONO ; // hold the pinNumber of each GPIO Used
int NUMLEDS ; // Number of leds per panel or strip
long defColor ; // defaulted color when loading
bool panelEnabled ; // tell if panel is enabled or not
class strip ; // reference to object created by adafruit constructor
};
The idea is to use as much as 4 gpio to control 4 different strip of panel or strip of led and use the methods for each object for each strip in use.
So far i'm unable to store and use the object of each Adafruit methods, since the initialisation method do not initialise the 4 element of an array that contains 4 structure each referencing a different object.
Here is how i define the initialisation of those array.
// define the number of panels that we use
int numberOfPanels = 2;
const int GPIO1=2 ;
const int GPIO2=4 ;
const int GPIO3=5 ;
const int GPIO4=16 ;
// only serve as an example here
// Create 4 strip lights independently for each gpio port
Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(256,GPIO1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(256,GPIO2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(256,GPIO3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(256,GPIO4, NEO_GRB + NEO_KHZ800);
struct ledPanels numPanels[]= {
{GPIO1,30,false,strip0},
{GPIO2,30,false,strip1},
{GPIO3,30,false,strip2},
{GPIO4,30,false,strip3}
};
// store the object reference to the array of pads
numPanels[0].strip = strip0 ; numPanels[1].strip = strip1 ; numPanels[2].strip = strip2; numPanels[3].strip = strip3 ;
// define the default color of each panel
numPanels[0].defcolor = numPanels[0].strip.Color(RED,NONE,NONE) ;
numPanels[1].defcolor = numPanels[1].strip.Color(NONE,GREEN,NONE) ;
numPanels[2].defcolor = numPanels[2].strip.Color(NONE,NONE,BLUE) ;
numPanels[3].defcolor = numPanels[3].strip.Color(MIDDLE,MIDDLE,MIDDLE) ;
So basicly what happend id when i try to access numPanels[x].defcolor or other properties of the structure, the compiler return an error like
error: cannot convert 'Adafruit_NeoPixel' to 'bool' in initialization
63 | {GPIO1,30,false,strip0},
I think thatif i can resolve the problem i will be good for the rest of the project, what i don't understand is why i can't store the values in numPads[x] as it always return an error that numPads did not define a type. I try many different syntax and position inside the code to try to resolve this, i went on different sites showing how i should declare the array, but nowhere i found an example that work so the numPads[x] is defined and can be used to change it's properties inside the struct variables, it's like the numPads[x] is never created and can not be accessed.
So if anyone have an idea of how i should declare, initialise and use the methods of each different strips created, that wold be very helpfull.
NOTE: I am a long time programmer and i never used C++ syntax, i understand the programming and methodologies of the language but one thing i'm having a lot of difficulties id the syntax of the compiler in Adruino or c++ with the thing as reference by pointers or address of the variable in memory.
So please help me Thanks to you all.