Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void writeFloat(unsigned int addr, float x)
- {
- byte seriesOfBytes[3];
- *((float *)seriesOfBytes) = x;
- // Write all four bytes.
- for(int i = 0; i < 4; i++)
- {
- i2c_eeprom_write_byte(0x57, addr, myFloat.bytes[i]); // Write byte to EEPROM
- Serial.println(seriesOfBytes[i],BIN); // Debug line
- }
- }
- 00000011
- 01010111
- 01101000
- 10100010
- 00101000
- 11011010
- 01010101
- 01001100
- byte *b = (byte *)&floatVal;
- union {
- float fval;
- byte bval[4];
- } floatAsBytes;
- floatAsBytes.fval = floatVal;
- EEPROM.write(0, floatAsBytes.bval[0]);
- EEPROM.write(1, floatAsBytes.bval[1]);
- EEPROM.write(2, floatAsBytes.bval[2]);
- EEPROM.write(3, floatAsBytes.bval[3]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement