Not gonna worry about how many writes and wipes the eeprom can do before burning out. The esp32 is sold at a reasonable rate so I can just replace it if I need to. Though I doubt ill make it to a hundred thousand writes/wipes.
Meanwhile I have a couple more structures to save to eeprom. This didn't work for some reason when the board is powered off and repowered. As long as the board is powered though it works. Meaning it works til powered off. Do I need to add read or something to the get part of the code since I have to use commit to actually save it to eeprom correctly?
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 cameraX;
int cameraY;
int player_direction;
int player_directionRepeat;
};
Player player = { 160, 170, 16, 16, 3, -128, -254, 2, 0};
struct Slot {
int slot_x;
int slot_y;
int slot_w;
int slot_h;
uint8_t itemId;
uint8_t quantity;
};
Slot slots[NUMBER_OF_SLOTS] = {
{ 180, 16, 81, 16, SLOT_AVAILABLE},
{ 180, 34, 81, 16, SLOT_AVAILABLE},
{ 180, 52, 81, 16, SLOT_AVAILABLE},
{ 180, 70, 81, 16, SLOT_AVAILABLE},
{ 180, 88, 81, 16, SLOT_AVAILABLE},
{ 180, 106, 81, 16, SLOT_AVAILABLE},
{ 180, 124, 81, 16, SLOT_AVAILABLE},
{ 180, 142, 81, 16, SLOT_AVAILABLE},
{ 180, 160, 81, 16, SLOT_AVAILABLE},
{ 180, 178, 81, 16, SLOT_AVAILABLE},
{ 180, 196, 81, 16, SLOT_AVAILABLE},
{ 180, 214, 81, 16, SLOT_AVAILABLE},
};
void save()
{
EEPROM.put(0, player);
EEPROM.put(36, slots);
EEPROM.commit();
}
void load()
{
EEPROM.get(0, player);
EEPROM.get(36, slots);
}