Saving and writing to eeprom
Posted: Fri Feb 09, 2018 10:32 pm
hi guys
I'm trying to save a player structure for a game I'm building to eeprom so I can retrieve it later. the esp32/Arduino library is different from the Arduino library so I'm having some problems.
ive got the address part down I think but its giving me a problem with the value which should be the player structure. but when I put player as the value it gives me errors. Can someone please help me?
I'm trying to save a player structure for a game I'm building to eeprom so I can retrieve it later. the esp32/Arduino library is different from the Arduino library so I'm having some problems.
ive got the address part down I think but its giving me a problem with the value which should be the player structure. but when I put player as the value it gives me errors. Can someone please help me?
Code: Select all
void setup() {
while (!Serial && (millis() < 4000)) ;
Serial.begin(115200);
tft.begin();
tft.setRotation(3);
tft.fillScreen(BLACK);
//tft.setFrameRate(60);
tft.persistence = false;
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
if (!ss1.begin(0x49)) {
Serial.println("ERROR!");
while (1);
}
if (!ss2.begin(0x4a)) {
Serial.println("ERROR!");
while (1);
}
else {
Serial.println("seesaw started");
Serial.print("version: ");
Serial.println(ss1.getVersion(), HEX);
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
ss1.pinModeBulk(button_mask, INPUT_PULLUP);
ss1.setGPIOInterrupts(button_mask, 1);
pinMode(IRQ_PIN1, INPUT);
/////////////////////////////////////////////////////////
ss2.pinModeBulk(button_mask2, INPUT_PULLUP);
ss2.setGPIOInterrupts(button_mask2, 1);
pinMode(IRQ_PIN2, INPUT);
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
if (!EEPROM.begin(EEPROM_SIZE))
{
Serial.println("failed to initialise EEPROM"); delay(1000000);
}
Serial.println(" bytes read from Flash . Values are:");
for (int i = 0; i < EEPROM_SIZE; i++)
{
Serial.print(byte(EEPROM.read(i))); Serial.print(" ");
}
Serial.println();
Serial.println("writing random n. in memory");
tft.useFrameBuffer(use_fb);
}
struct Player
{
int player_x;
int player_y;
int w;
int h;
int room;
int player_direction;
int player_directionRepeat;
};
Player player = { 160, 170, 16, 16, 3, 2, 0};
byte saveKey = 121;
int val = byte(random(10020));
void save()
{
EEPROM.write(0, saveKey);
Serial.print(val); Serial.print(" ");
EEPROM.write(28, player);
Serial.print(val); Serial.print(" ");
Serial.print("saved");
}