For a first program, I’ve seen a lot worse.
I could understand what most of your code was doing, which is always a good thing. Some people are capable of writing programs that do amazing things but end up with nearly illegible code.
The by-value instead of by-reference thing is completely expected,
some people get quite far into C++ without knowing about references.
The EEPROM problem is the only thing I’d call a serious bug because it’s the only thing that actually has a negative impact. 99% of bugs can’t actually harm the console in any way, this is one of those extremely rare cases where there were non-obvious implications that could cause harm (although still in a fairly limited way).
Essentially you didn’t “mess-up pretty bad”, you made a beginners mistake, you just got a bit unlucky as to which mistake that was.
I’ve forked your repo and uploaded all my changes to my fork in a single commit.
I’ve commented all the changes I made to try to explain why I made them.
Rather than following your naming conventions and brace style, I followed my own preferred style, partly because I can write faster that way, partly so it’ll stand out more.
Some of my changes are changes that are ‘subjectively better’ (i.e. other programmers might disagree). When it comes to programming, some things are clear cut and others are eternally debated.
I’m prepared to explain every single change if you have any questions.
Also note that I didn’t put saving functionality in because I wasn’t sure which button combos you’d want for saving and loading or whether you were planning to add some kind of menu for that.
Saving is fairly easy though, you’d just have to loop through all the points and write them to EEPROM using EEPROM.put
like so:
Edit: Almost forgot EEPROM_STORAGE_SPACE_START
.
(Though ideally you should offset the address a bit. A lot of games write straight to EEPROM_STORAGE_SPACE_START
and as a side effect it causes that area of EEPROM to wear out faster than later areas because of all the games picking that area.)
for(size_t i = 0, addr = EEPROM_STORAGE_SPACE_START; i < ArduArt::maxPoints; ++i, addr += sizeof(Point2))
{
EEPROM.put(addr, arduart.points[i]);
}
Edit: or (subjectively more readable), this version:
size_t addr = EEPROM_STORAGE_SPACE_START;
for(size_t i = 0; i < ArduArt::maxPoints; ++i)
{
EEPROM.put(addr, arduart.points[i]);
addr += sizeof(Point2);
}
And EEPROM.get
can do the reverse.
You could improve that by saving the number of points before actually saving the points, so instead of checking for a special value (i.e. -1), you could just limit the number of points you load (which would also be slightly faster).
I’ll leave you to have a go at doing that yourself first.
Like I said, your code isn’t bad, it’s quite well written.
You’re just lacking knowledge, and nobody can blame you for that.