So I'm working on a big code right now, for a game, but there's a problem with my EEPROM, I've never used it before and after a lot of tests I think I knew how it worked. I want to use the EEPROM to save a highscore. Since my code is 370 lines in total I'll only show the parts with the EEPROM that are important. I saw Paul (or someone similair) on an EEPROM thread saying that it can only store like 8 bytes or something, I can vaguely remember something like that.
Here's the part of the code:
#include <EEPROM.h>
float highscore;
int address = 0;
void setup() {
Serial.begin(9600);
.....
void loop() {
// the loop that runs after you won a game that checks for new highscore:
............
highscore = EEPROM.read(address);
if (finalTime / 60 < highscore) {
highscore = finalTime / 60; // / 60 because I want to see it in minuts.
EEPROM.write(address, highscore);
}
if (finalTime / 60 > highscore) {
Serial.println("No new highscore");
}
.................
}
So I've set the EEPROM to 3 (minuts) multiple times, and then it'll work once fine, and after that the highscore will be 0.00, someone knows why? I think I'm making a stupid mistake.
Delta_G:
Sigh. You know the problem isn't in these lines. Why don't you either go through the rest of your code and find the mistake or post it here so we can look.
Well the code is 380 lines so I don't know if you want to go through that whole. But it can't actually be in the other because they have nothing to do with the highscore or EEPROM at all.
Would EEPROM.get() and EEPROM.put() work for this? Not sure. I don't think I've ever had to do this where I couldn't easily split up the bytes of what I was storing manually, so I haven't played with get and put.
Ooohhh my bad! So basically it returns 0.00.
But at first when I set it to 2.00 (min) and I receive a new highscore it's working and it says "new highscore "new time"" let's say the time is 1.87 min, next time when I do it, it says just 0.00 "No highscore".
Delta_G:
Ok. If you're not going to show any code and insist that I solve this by guessing then I'm out. I hope someone else can guess your problem. If not, then when you decide you want to solve it come back and post the code.
I don't get why you immediately get mad on me, I already told you that this is the whole code for the EEPROM, the other part is seperated from this part. I'm not someone who knows everything so there's no need to say that I 'refuse' and didn't 'answer' questions while you didn't even read it.
Instead just don't immediately get mad on people, I'm just asking for help and giving the most information as I can, fine if you don't want to help then don't.
Have you by any chance got 2 or more variables with the same name in different scopes and maybe even different types ?
We cannot tell because you have not posted your complete program.
No Bob I haven't :D, but you guys get me wrong I think, this is the whole code, but seperated from another code because it's bugged, this code itself glitches.