Am trying to optimise some code for a "programmable IR remote".
It is probably quite inefficient in it's usage of variables for the 'mark and space' sequences (pulse trains) but for now, i'm interested in the basic theory of manipulating multi-dimensional arrays.
I had previously been using a global variable for each 'button sequence' and then calling them in a function repeatedly for each button - this ended up eating up a lot of memory.
So; i am now trying to localise the variables to save memory space.
PRESENT setup:
const int remoteONE[] = {4200, 500, 1200, 3400, 200};
const int remoteTWO[] = {4200, 1500, 200, 3400, 300};
const int remoteTHREE[] = {4200, 500, 1200, 1400, 200};
const int remoteFOUR[] = {4200, 500, 1200, 3400, 1200};
and then called by;
(for a particular sequence)
sendCode(remoteTHREE);
sendCode(remoteONE);
sendCode(remoteTWO);
sendCode(remoteONE);
my idea is to place the remoteXXX variables into ONE array within the sendCode() function which can then be called by a parameter of its index;
IMPROVED (in my mind) setup:
void sendCode(int idx) {
const int remoteALLNUM[4][5] = {(4200, 500, 1200, 3400, 200),
(4200, 1500, 200, 3400, 300),
(4200, 500, 1200, 1400, 200),
(4200, 500, 1200, 3400, 1200)};
code2send=remoteALLNUM[idx]; // or something of this sort - obviously this is wrong.
}
the issue is; if i declare as remoteALLNUM[4][5] = {.... etc....
then i can call x = remoteALLNUM[2][1]
but this only gives a single int, whereas i want the whole array.
if i don't initialize the array explicitly and just use; remoteALLNUM[] = {.... etc....
calling x = remoteALLNUM[2]
gives only the last member - same problem.
how should i be using this array setup ?
i'm sure the whole variable usage and code structure for the Remote Program could be much better, but for now - am just concentrating on the array manipulation.
Thanks.