Help with a 7-Segment Display and EEProm

Hello, I am working on a project for an engineering class. In our case, we are to design a game that uses a 7-segment display and an 8x8 LED matrix. Our group is doing a kind of “Rock, Paper, Scissors” game that uses the matrix to show the sign the player chose, the sign the program generates, and then show which one wins. It’s fairly simple - but we also are supposed to include scoring. In this game, the 7-segment display is supposed to count up by one every time the player wins consecutively. If the computer wins, the score resets to zero. We also want the score to remain in memory for when the system is powered back on.

Our problem, I believe, is in the EEprom command. I initialized the 7-seg to display a zero - and that works just fine, but it clearly isn’t getting the memo to count up by one when it is supposed to. It simply remains at zero. I’ve tried to wrap my head around the EEProm commands, but this is as far as I can get. I am obviously a novice programmer and I’m not sure where to start. If someone could point me in the right direction to get the display counting, that’d be great.

Note: I am using a common anode 7-segment display, so the output going low triggers each segment to go high. Any help is appreciated. I’m sure it’s something small and silly.

arduino_code_final.ino (12.5 KB)

Get the game working without EEPROM first. You can easily add in the EEPROM stuff later. The EEPROM stuff is pointless if the basic game does not work correctly.

The game itself works wonderfully. The 7-segment display does not count up. Is your suggestion to get it to count before making it remember the score?

int newscore = EEPROM.read(addr);

Executable code, like EEPROM.read(), must be in a function.

Your code has useless curly braces, no comments, and is piss-poorly indented. The last there is no excuse for, since there is an item on the Tools menu, Auto Format, that will correct that.

If you prefer the (horrid) style where the { goes on the line with the function or statement, at least put a space between the ) and the {.

kheyer1 wrote (in part):

Is your suggestion to get it to count before making it remember the score?

Yes. Exactly.

If necessary, create a separate program that displays a zero, then a one, then a two, ... , then an eight, then a nine.

Get this part working before you attempt to store or retrieve data in EEPROM.

Paul, your comment came off as a little aggressive. About 85% of this code was provided to us by the school to get us started, so I didn’t create all the curly braces and formatting issues.

Our expectation is to build the project, modify it aesthetically and through some programming, and spit out a finished product in a few weeks. We are all new to this - no one learns programming overnight.

Anyway, I have gone back to an earlier sketch, and the game now counts correctly on the 7-segment display. Perhaps someone could explain exactly how EEPPROM works for me, since the Arduino website words it in a way I cannot quite understand. This, quite literally, is in a different language. I’m just trying to learn it any way I can so I can gain understanding of what each thing does and how.

Thank you to those who are helping me. Here is my current code. (Autoformatted now :slight_smile: )

Heyer_Kyle_004_Code_Modified.ino.ino (12.8 KB)

kheyer1:
Anyway, I have gone back to an earlier sketch, and the game now counts correctly on the 7-segment display. Perhaps someone could explain exactly how EEPPROM works for me, since the Arduino website words it in a way I cannot quite understand. This, quite literally, is in a different language. I'm just trying to learn it any way I can so I can gain understanding of what each thing does and how.

Not sure what's not to understand about EEPROM. It's a bucket of bytes that your sketch can use however it likes. Each time the score changes, write it to your chosen location (location zero is always a good pick). When your sketch starts (ie: in setup()), read the value out of the EEPROM and initialise your counter variable.

PaulMurrayCbr:
Not sure what's not to understand about EEPROM. It's a bucket of bytes that your sketch can use however it likes. Each time the score changes, write it to your chosen location (location zero is always a good pick). When your sketch starts (ie: in setup()), read the value out of the EEPROM and initialise your counter variable.

Again, this is the first time that anyone in our group has programmed anything. You have to assume that you are explaining this to a five-year old. I've been reading up on how it works - so I get what it does conceptually, but not in practice.

What I'm not understanding is how you implement (in the program) the EEPROM command to, in this case, to remember on startup the last configuration of a 7-segment display.

In addition, when the player wins the first time the game is played after it's turned on, the 7-seg also counts up by two. Every time the player wins from there on out, it counts up by one normally. And from what I can tell, I didn't add any code saying to do that.

It would just help if someone could show how the command would work with my code. No one learned to program overnight, so I would also appreciate if some could stop assuming I know everything from the start.

And I forgot to insert the newest code draft. Here is that part.

Heyer_Kyle_004_Code_Modified.ino.ino (12.8 KB)