I think I lost my whole C++ knowledge...
What I want is to initialize a 2D unsigned char array in a proper (readable) way: My approaches:
#define RADIO_ONOFF 0
#define RADIO_P1 1
#define RADIO_P2 2
...
#define NR_OF_CODES = 5
#define CODE_LENGTH = 10
#1:
unsigned char** codes = new unsigned char*[NR_OF_CODES];
codes[RADIO_ONOFF] = new unsigned char[CODE_LENGTH]{ 9,180,88,11,33,4,0,255,64,191 }; // does not work
...
#2:
unsigned char ICODES[NR_OF_CODES][CODE_LENGTH];
ICODES[RADIO_ONOFF] = { 9,180,88,11,33,4,0,255,64,191 }; // same as above
...
#3:
class Test {
private:
unsigned char data[CODE_LENGTH];
public:
Test(unsigned char a1, unsigned char a2, unsigned char a3, unsigned char a4, unsigned char a5, unsigned char a6, unsigned char a7, unsigned char a8, unsigned char a9, unsigned char a10);
unsigned char* getData(void);
};
Test::Test(unsigned char a1, unsigned char a2, unsigned char a3, unsigned char a4, unsigned char a5, unsigned char a6, unsigned char a7, unsigned char a8, unsigned char a9, unsigned char a10) {
this->data[0] = a1;
this->data[1] = a2;
this->data[2] = a3;
this->data[3] = a4;
this->data[4] = a5;
this->data[5] = a6;
this->data[6] = a7;
this->data[7] = a8;
this->data[8] = a9;
this->data[9] = a10;
}
unsigned char* Test::getData(void) {
return data;
}
void setup() {
test[RADIO_ONOFF] = new Test( 9,180,88,11,33,4,0,255,64,191 );
test[RADIO_P1] = new Test( 9,180,88,11,33,4,0,255,64,192 );
...
}
#4
const unsigned char RADIO_ONOFF[] = { 9,180,88,11,33,4,0,255,64,191 };
const unsigned char RADIO_P1[] = { 9,180,88,11,33,4,0,255,64,192 };
...
Error message I get for #1 and #2: (code should compile for Arduino and it needs a setup-function)
In function 'void setup()': revTest:58: error: expected primary-expression before '{' token revTest:58: error: expected `;' before '{' token
OK - my questions:
To me - #3 and #4 are nice and readable. Effort for #3 is the highest - but I think it´s the fastest way if I want do uses the array in a switch statement. - True?
I thought array initialization in #1 and #2 should work this way????
Very Arduino specific:
I am not sure what has to be defined inside of setup() and what should go outside of setup(). static initialization and global outside, dynamic inside or what?
I have red about PROGMEM for Arduino - I think it´s not worth the effort in this case. I am right? (I think I`ll have about 50 different codes...)
thx!