I have a little snippet of code which writes to an I2C sensor of mine. However, I noticed an odd behavior. If I pass the address of the byte through the function, it requires an "in file".
Function:
int readRange(byte Sensor) {
Wire.beginTransmission(Sensor);
Wire.write(0x00); // Open register for sending command
Wire.write(0x51); // Send ranging command
Wire.endTransmission();
delay(100);
Wire.beginTransmission(Sensor);
Wire.write(0x02); // Open register for reading data
Wire.endTransmission();
Wire.requestFrom(Sensor,2);
while (Wire.available() < 2) ;
byte highByte = Wire.read();
byte lowByte = Wire.read();
return ((highByte << 8) + lowByte);
}
Console output:
In file included from srf_code.cpp:1:0:
/usr/share/arduino/libraries/Wire/Wire.h: In function 'int readRange(byte)':
/usr/share/arduino/libraries/Wire/Wire.h:58:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int)
/usr/share/arduino/libraries/Wire/Wire.h:56:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)
However, if I don't pass the byte in the beginning (the way I had it in an earlier revision of the code), and just have the sensor address in-line, it doesn't include anything.
Function definition:
int readRange()
Why does it do this? Is this a bad programming practice? It seems to work fine when I upload it.