Hello AWOL
Apologies for the spoon-fed session but I'm just not getting any joy. I've referenced the union as you've stated:
union Distance
{
long Distance;
byte Received_Byte_Array[4];
} Distance;
Then I tried to compile but I'm still getting the issue of Received_Byte_Array not declared. I then looked at the post from the first link again and tried to accomplish it as PaulS said in that post:
stuff sensorData;
sensorData.bytes[0] = firstValue;
sensorData.bytes[1] = secondValue;
sensorData.bytes[2] = thirdValue;
sensorData.bytes[3] = fourthValue;
My version being:
if (Wire.available()) // slave may send less than requested
{
Distance;
Received_Byte_Array[0] = Wire.read();
Received_Byte_Array[1] = Wire.read();
Received_Byte_Array[2] = Wire.read();
Received_Byte_Array[3] = Wire.read();
}
I also tried:
for ( int i = 0; i < 4; i++)
{
Distance Received_Byte_Array[i] = Wire.read();
}
as well as:
for ( int i = 0; i < 4; i++)
{
Distance; Received_Byte_Array[i] = Wire.read();
}
Still nothing, apologies if I'm being a nuisance but I'm not finding any examples of this.