Hi All
Ive looked everywhere to try and figure out what Im doing wrong, but just cant get on top of this one. My sketch is using 4 functions for sending / receiving serial / IR + one function for translation between each of them. I have a bunch of arrays that I want the IR transmit function to use for timings, but I want to keep them as global constants, and have the translator send the IR transmit function the pointer to the array of timing ints. Ive tried what I thought were correct calls with & and * but cant make it work correctly.
Outside functions:
const int IRvoldown[]={600,500,400,300,200,100};
const int IRvolup[]={100,200,300,400,500,600};
In translator function:
if..... IRTX(IRvolup);
if..... IRTX(IRvoldown);
etc
IR TX function:
void IRTX(int IRTXcommand){
Serial.println("IRTX: Received Data");
Serial.print("IRTX: size of IRTXcommand is ");
Serial.println(sizeof(IRTXcommand));
Serial.print("IRTX: size of IRTXcommand[0] is ");
Serial.println(sizeof(IRTXcommand[0]));
for( int i=0;i < (sizeof(IRTXcommand)/sizeof(IRTXcommand[0]));i++){
Serial.print("IRTX: i is ");
Serial.print(i);
Serial.print(". Value is ");
Serial.println(IRTXcommand[i]);
}
Serial.println("IRTX: Just to prove the data is there: ");
for( int i=0;i < 6;i++){
Serial.print("IRTX: i is ");
Serial.print(i);
Serial.print(". Value is ");
Serial.println(IRTXcommand[i]);
}
}
Output is:
TRANSLATION: received SX, command 204500
IRTX: Received Data
IRTX: size of IRTXcommand is 2
IRTX: size of IRTXcommand[0] is 2
IRTX: i is 0. Value is 600
IRTX: Just to prove the data is there:
IRTX: i is 0. Value is 600
IRTX: i is 1. Value is 500
IRTX: i is 2. Value is 400
IRTX: i is 3. Value is 300
IRTX: i is 4. Value is 200
IRTX: i is 5. Value is 100
As you can see, the problem is that the sizeof() reports just the int size of 2, instead of proper length
If I put:
- in like this: IRTX(*IRvolup);
& in the function like this: void IRTX(int &IRTXcommand){
I get errors:
Full_System_just_working_on_IR_20110908.cpp: In function 'void translation(char, String)':
Full_System_just_working_on_IR_20110908:74: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
Full_System_just_working_on_IR_20110908:8: error: in passing argument 1 of 'void IRTX(int&)'
Full_System_just_working_on_IR_20110908:77: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
Full_System_just_working_on_IR_20110908:8: error: in passing argument 1 of 'void IRTX(int&)'
Full_System_just_working_on_IR_20110908.cpp: In function 'void IRTX(int&)':
Full_System_just_working_on_IR_20110908:93: error: invalid types 'int[int]' for array subscript
Full_System_just_working_on_IR_20110908:94: error: invalid types 'int[int]' for array subscript
Full_System_just_working_on_IR_20110908:98: error: invalid types 'int[int]' for array subscript
Full_System_just_working_on_IR_20110908:105: error: invalid types 'int[int]' for array subscript
Thanka a lot!
regards
Andrew