SHARE
TWEET

Untitled

a guest Jul 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void writeFloat(unsigned int addr, float x)
  2. {
  3.   byte seriesOfBytes[3];
  4.   *((float *)seriesOfBytes) = x;
  5.   // Write all four bytes.
  6.   for(int i = 0; i < 4; i++)
  7.   {
  8.     i2c_eeprom_write_byte(0x57, addr, myFloat.bytes[i]); // Write byte to EEPROM
  9.     Serial.println(seriesOfBytes[i],BIN);  // Debug line
  10.   }
  11. }
  12.      
  13. 00000011
  14. 01010111
  15. 01101000
  16. 10100010
  17.      
  18. 00101000
  19. 11011010
  20. 01010101
  21. 01001100
  22.      
  23. byte *b = (byte *)&floatVal;
  24.      
  25. union {
  26.     float fval;
  27.     byte bval[4];
  28. } floatAsBytes;
  29.  
  30. floatAsBytes.fval = floatVal;
  31. EEPROM.write(0, floatAsBytes.bval[0]);
  32. EEPROM.write(1, floatAsBytes.bval[1]);
  33. EEPROM.write(2, floatAsBytes.bval[2]);
  34. EEPROM.write(3, floatAsBytes.bval[3]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top