Saving String to EEPROM

Hi, Just signed up cus i am in need of some help.

Im very new to Arduino and C/C++ but i have used other programming languages.

I'm trying t create a game where you press a button when a purple light is on and m trying to save the high score and the name of the person who got it to eeprom. i've searched around for ages and have seen many ways but never been able to understand them enough to apply them to my code. Could someone help me?

Here's the code i have written. It currently does not compile:

int TurnCounter;
int WinCounter = 0;
int TotalTurns = 0;
int HighScore;
#include <EEPROM.h>
String Name;

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT); //RED LED
  pinMode(12, OUTPUT); //BLUE LED
  pinMode(11, OUTPUT); //YELLOW LED 4
  pinMode(10, OUTPUT); // RED LED 3
  pinMode(9, OUTPUT); // YELLOW LED 3
  pinMode(8, OUTPUT); // RED LED 2
  pinMode(7, OUTPUT); // YELLOW LED 2
  pinMode(6, OUTPUT); // RED LED 1
  pinMode(5, OUTPUT); // YELLOW LED 1
  pinMode(4, INPUT); //THIS THE PIN FOR THE BUSH BUTTON
  HighScore = EEPROM.read(0);

  Serial.begin(9600);
  Serial.println("Can you please enter your name in the box above and press enter");
  delay(7000);

  if (Serial.available() > 0) {
    Name = Serial.readString();
  }

  Serial.print("Your name is ");
  Serial.println(Name);
  Serial.println("THERE ARE 7 ROUNDS TO THIS GAME. ALL YOU HAVE TO DO IS PRESS THE BUTTON WHEN THE PURPLE LIGHT IS ON.");
  Serial.print("THE BEST SCORE IS ");
  Serial.print(HighScore);
  Serial.print(" AND THIS WAS COMPLETED BY ");
  int i = 0;
  int value = 0;
  for (int i = 1; i = 15; i++) {
    value = EEPROM.read(i);
    char MyCharacter = char(value);
    Serial.print(MyCharacter);
  }
}

void loop() {
  LEDs_1(); //THIS RUNS THE PROCEDURE STARTS THE LED FLASHING SEQUENCE
  STOP();
  LEDs_2();
  STOP();
  LEDs_3();
  STOP();
  LEDs_4();
  STOP();
  LEDs_5();
  STOP();
  LEDs_6();
  STOP();
  LEDs_7();
  STOP();
  LEDs_8();
  STOP_1();
}












void STOP() {
  int buttonState; //THIS CREATES A INTEGER VARIABLE FOR THE STATE OF THE BUTTON
  buttonState = digitalRead(4); //THIS LINE STORES THE STATE OF THE BUTTON IN THE VARIABLE

  if (buttonState == LOW) {
    Serial.println("UNLUCKY");
    TurnCounter += 1;
    Serial.print("That was attempt ");
    Serial.println(TurnCounter);
    delay(2500);;
    buttonState = digitalRead(4);
  }

}


void STOP_1() {
  int buttonState; //THIS CREATES A INTEGER VARIABLE FOR THE STATE OF THE BUTTON
  buttonState = digitalRead(4); //THIS LINE STORES THE STATE OF THE BUTTON IN THE VARIABLE
  if (buttonState == LOW) {
    TurnCounter += 1;
    TotalTurns += TurnCounter;
    Serial.println("YOU'VE WON");
    Serial.print("YOU BEAT THIS ROUND ON ATTEMPT ");
    Serial.println(TurnCounter);
    TurnCounter = 0;
    WinCounter += 1;
    if (WinCounter == 7) {
      Serial.print("CONGRATUALTIONS, YOU HAVE BEATEN THE GAME. IT TOOK YOU ");
      Serial.print(TotalTurns);
      Serial.print(" ATTEMPTS. THE HIGH SCORE IS ");
      Serial.println(HighScore);
      if (HighScore > TotalTurns) {
        EEPROM.write(0, TotalTurns);
        int letterNO;
        int address = 1;
        int from = 0;
        int to = 1;
        char letter;
        
         for (letterNO = 0; letterNO = Name.length(); ++letterNO) {
         letter = Name.substring(from, to));
          from += 1;
          to += 1;
          address += 1;
        }
        
        
        for (letterNO = 0; letterNO = Name.length(); ++letterNO) {
          EEPROM.write(address, letter);
          from += 1;
          to += 1;
          address += 1;
        }
       





        Serial.println("CONGRATULATIONS, YOU HAVE BEATEN THE HIGH SCORE");
        int x;
        for (x = 0; x = 5; ++x) {
          digitalWrite(5, HIGH);
          digitalWrite(6, HIGH);
          digitalWrite(7, HIGH);
          digitalWrite(8, HIGH);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(13, HIGH);
          delay(1000);
          digitalWrite(5, LOW);
          digitalWrite(6, LOW);
          digitalWrite(7, LOW);
          digitalWrite(8, LOW);
          digitalWrite(9, LOW);
          digitalWrite(10, LOW);
          digitalWrite(11, LOW);
          digitalWrite(12, LOW);
          digitalWrite(13, LOW);
          delay(1000);

        }
      }
      else
      {
        Serial.println("UNLUCKY, YOU DID NOT BEAT THE HIGH SCORE. BETTER LUCK NEXT TIME.");
      }
    }
    delay(7500);
    buttonState = digitalRead(4);
  }
  else
  {
    delay(0);
  }

}









void LEDs_1() {
  digitalWrite(5, HIGH); //Turns on YELLOW LED 1
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);  //THESE LINES TURN OFF ALL THE OTHER LEDs
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  Delay();
  STOP();
  Delay();
}

void LEDs_2() {
  digitalWrite(5, LOW); //Turns off YELLOW LED 1
  digitalWrite(6, HIGH); //Turns on REd LED 1
  Delay();
  STOP();
  Delay();
}

void LEDs_3() {
  digitalWrite(6, LOW); //Turns off REd LED 1
  digitalWrite(7, HIGH); //Turns on YELLOW LED 2
  Delay();
  STOP();
  Delay();
}

void LEDs_4() {
  digitalWrite(7, LOW); //Turns off YELLOW LED 2
  digitalWrite(8, HIGH); //Turns on REd LED 2
  Delay();
  STOP();
  Delay();
}

void LEDs_5() {
  digitalWrite(8, LOW); //Turns off RED LED 2
  digitalWrite(9, HIGH);  //Turns on YELLOW LED 3
  Delay();
  STOP();
  Delay();
}

void LEDs_6() {
  digitalWrite(9, LOW); //Turns off YELLOW LED 3
  digitalWrite(10, HIGH);  //Turns on RED LED 3
  Delay();
  STOP();
  Delay();
}

void LEDs_7() {
  digitalWrite(10, LOW); //Turns off RED LED 3
  digitalWrite(11, HIGH);  //Turns on YELLOW LED 4
  Delay();
  STOP();
  Delay();
}

void LEDs_8() {
  digitalWrite(11, LOW); //Turns off YELLOW LED 4
  digitalWrite(12, HIGH); //TUrns on the BLUE LED.
  digitalWrite(13, HIGH); //Turns on the RED LED. THIS WITH THE BLUE CREATES PURPLE
  Delay();
  STOP_1();
  Delay();
}


void Delay() {
  if (WinCounter == 0) {
    delay(100);
  }
  else if (WinCounter == 1) {
    delay(75);
  }
  else if (WinCounter == 2) {
    delay(62.5);
  }
  else if (WinCounter == 3) {
    delay(50);
  }
  else if (WinCounter == 4) {
    delay(37.5);
  }
  else if (WinCounter == 5) {
    delay(15);
  }
  else if (WinCounter == 6) {
    delay(5);
  }
}

It doesn't comply with the specification?

Where are the code tags?

  delay(62.5);

Since when does delay accept fractions?

for (int i = 1; i = 15; i++) ``for (x = 0; x = 5; ++x)
oops

AWOL:
It doesn't comply with the specification?

Where are the code tags?

I meant it brought up an error message

and sorry i forgot to put in the code tags

JH_01_17:
I meant it brought up an error message

And you thought we'd like to guess what that message is?

No thanks.

AWOL:
And you thought we'd like to guess what that message is?

No thanks.

Here you go...

Arduino: 1.8.2 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\czharrap\Documents\Arduino\Flashing_LED_Game\Flashing_LED_Game.ino: In function 'void STOP_1()':

Flashing_LED_Game:116: error: cannot convert 'String' to 'char' in assignment

letter = Name.substring(from, to));

^

exit status 1
cannot convert 'String' to 'char' in assignment

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

charAt instead?

(Sorry, I don't use String)

JH_01_17:
I meant it brought up an error message

and sorry i forgot to put in the code tags

the library lets you read/write an object:

#include <EEPROM.h>

struct LeaderBoard{
  int highScore;
  char currentChamp[20];
};

LeaderBoard leader = {0,"unknown"};

void setup() 
{
  EEPROM.get(0,leader);
  Serial.println(leader.highScore);
  Serial.println(leader.currentChamp);
}

void loop() 
{
  // leader.highScore = someInt;
  // EEPROM.put(0,leader);  to store
}

AWOL:

 for (int i = 1; i = 15; i++)
for (x = 0; x = 5; ++x)

oops

Look I'm a newbie. Please can you explain?

AWOL:
charAt instead?

(Sorry, I don't use String)

It's fine, your definitely going to be better then me. I'll google the function and see it will work. Thank you so much AWOL

Look I'm a newbie. Please can you explain?

Why not check the reference?
It's what it's there for.

(s)he's pointing out a common mistake here:

for (int i = 1; i = 15; i++)

assignment operator: =
comparison operator: ==

BulldogLowell:
the library lets you read/write an object:

#include <EEPROM.h>

struct LeaderBoard{
  int highScore;
  char currentChamp[20];
};

LeaderBoard leader = {0,"unknown"};

void setup()
{
  EEPROM.get(0,leader);
  Serial.println(leader.highScore);
  Serial.println(leader.currentChamp);
}

void loop()
{
  // leader.highScore = someInt;
  // EEPROM.put(0,leader);  to store
}

Please could you explain a bit more how to implement this into my code. Thanks

JH_01_17:
Please could you explain a bit more how to implement this into my code. Thanks

yes,

Save an object to EEPROM, not byte by byte. There is an official EEPROM post you can use to learn how to use the well documented class.

Also, stay away from the String class and use C strings instead. You're likely to find more posts on that topic than would fit into a uint16_t.