Retrun 2 value from an array of bytes

Hello, I have an array of bytes called values I need to extract bytes at positions 6 and 7 where it should be saved the temperature info of my sensor how can I do it?

byte temperature(){
  Serial.println("---VV---");
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(20);
  Serial.flush();

  if(mod.write(msgt,sizeof(msgt))==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
 
    for(byte i=0;i<10;i++){
    values[i] = mod.read();
    Serial.print("|");
    Serial.print(values[i],HEX);
   
    }
   
    Serial.println("-----");
    Serial.flush();
    delay(3000);

  }
// I'm try to return the value that should be host at position 6 and 7
  return values[6,7];
}

for example:

here my values array: |1|3|4|3|E8|1|3F|3B|C3|

it should return 13F

Imho a simple solution would be that you return already a two byte integer, not an array.

int temperature(){
/*
  other stuff
*/
  int result = ((int)value[5] << 8) | value[6];   // shift one  byte and add the other, 
  //  int result = ((int)value[6] << 8) | value[5];  // alternative if you need the temperature in the other order
  Serial.println(result, HEX); // just to check if the order of bytes is as you need them
  Serial.println(result); 
  return result;
}

Agree with @noasica.

If you really want to return 2 separate bytes, you can put them in a struct or you can add two byte addresses as parameters to your function.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.