//**************************************************************************
// Flavio Fernandes
// 16/04/2022
// Exemplo de como gravar na EEPROM uma variavel de 32 bytes
//**************************************************************************
#include <EEPROM.h>
byte Var_32_Part_0, Var_32_Part_1, Var_32_Part_2, Var_32_Part_3, endereco = 0;
uint32_t var_32_bits = 3213254719, var_32_bits_out = 0;
void setup()
{
Serial.begin(115200);
// Truncamento da variavel de 32 para 8 bytes
Var_32_Part_3 = var_32_bits >> 24;
Var_32_Part_2 = var_32_bits >> 16;
Var_32_Part_1 = var_32_bits >> 8;
Var_32_Part_0 = var_32_bits;
EEPROM.write(endereco + 3, Var_32_Part_3);
EEPROM.write(endereco + 2, Var_32_Part_2);
EEPROM.write(endereco + 1, Var_32_Part_1);
EEPROM.write(endereco + 0, Var_32_Part_0);
Serial.print("Var_32_Part_3 → ");
Serial.println(Var_32_Part_3);
Serial.print("Var_32_Part_2 → ");
Serial.println(Var_32_Part_2);
Serial.print("Var_32_Part_1 → ");
Serial.println(Var_32_Part_1);
Serial.print("Var_32_Part_0 → ");
Serial.println(Var_32_Part_0);
Serial.print("Var_32 → ");
Serial.println(var_32_bits);
Serial.print("Var_32_OUT → ");
var_32_bits_out = (uint32_t)EEPROM.read(endereco + 0) |
((uint32_t)EEPROM.read(endereco + 1) << 8) |
((uint32_t)EEPROM.read(endereco + 2) << 16) |
((uint32_t)EEPROM.read(endereco + 3) << 24);
Serial.println(var_32_bits_out);
}
void loop()
{
}