Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LongToByte(long value, byte result[])
- {
- union
- {
- long value;
- byte bytes[4];
- } ul;
- ul.value = value;
- memcpy(result, ul.bytes, 4);
- }
- long GetLong(byte* source)
- {
- union
- {
- long value;
- byte bytes[4];
- } ul;
- memcpy(ul.bytes, source, 4);
- return ul.value;
- }
- long value = 2314;
- byte send[4];
- LongToByte(value, send);
- Wire.beginTransmission(device_id);
- Wire.send(send, 4); // byte array, size
- Wire.endTransmission();
- int position = 0;
- long value;
- byte read[4];
- while(Wire.available())
- {
- read[position++] = Wire.read();
- if(position == 4)
- {
- value = GetLong(read);
- Serial.println("Value: " + String(value));
- break;
- }
- }
Add Comment
Please, Sign In to add comment