Weird behaviour with RF24 and arrays

Hello everybody,

This is my first post so first of all, hello whoever is reading this ;D

Well my problem is this:

I've one sketch with NRF24L01 working fine, but the problem is
The emiter sketch is like this:

  //...more code there
  triggers[1] = analogRead(TRIGGER_LEFT);
  map_triggers[1] = map(triggers[1],0,674,0,1023); 
  if(map_triggers[1]!=map_old_triggers[1]){
     cValues[0] = TRIGGER_LEFT;
     cValues[1] = map_triggers[1];
     //sendControlValues(cValues);
     radio.write(cValues, sizeof(cValues));
     }
  map_old_triggers[1] = map_triggers[1];
  //...more code there

On receiver sketch simply this:

//...more code there
while(radio.available()){
    radio.read(&value, sizeof(value));
    Serial.print(" Pin=");
    Serial.print(value[0]);
    Serial.print(" Value=");
    Serial.println(value[1]);
  }
//...more code there

The sketches over here work perfectly, i receive both values of the array perfectly, but as I've to manage more triggers and joystick axes an add some sentences on each I prefer to do a function so i can send the arrays of several analogic sources, below it's the function:

void sendControlValues(int Values[2]){
  bool ok = radio.write(Values, sizeof(Values) );
  if (ok){
    Serial.print(" OK!");
  }
  else{
    Serial.println(" FAIL!");
  }
}

And now the problem, while on the first case (without the function) I'm receiving perfectly both array values (value[0] and value[1]) on the second case I'm only receiving value[0] correctly, value[1] it's always 0 on receiver!!!

Inside the sendControlValues() if I print value[0] and value[1] it's printing the required value, print what should be printed but anyway I'm receiving always 0 at value[1] of the receiver.

I don't understand what I'm doing wrong. Simple case works perfectly but just inside a function not... :sob:

Thanks for your help :-[

Look at sizeof(Values):

void sendControlValues(int Values[2]) {
  Serial.print(F("sizeof Values "));
  Serial.println(sizeof(Values));
}
int testArr[2];
void setup() {
  Serial.begin(115200);
  sendControlValues(testArr);
}
void loop() {}

sizeof Values 2
It returns the size of the pointer (this is passed to the routine), not the size of the array pointed to.

You are right!!!!

I've been googleing a while and I have read there is no "clean" way to get this work, so I decide to use a fixed and known size of value, in this case I use a value of "4" (bytes) and all works correctly

Thank you very much!!!

You could pass the length of the array in bytes to the function.
That would be the standard way to do it. :wink:

Yep I'll do that! thx