Hey everyone,
I have a question for an Arduino project that we are currently working on at home.
So the basic setup is the following:
- we have an Arduino Mega on a breadboard
- we have an Adafruit LED strip, consisting of 450 LEDs connected to it
- we have an arcade joystick also connected to the Arduino Mega
The LEDs are arranged in a way that they form a 15x30 matrix, where we project simple arcade games like Snake.
Now we added a SD card adapter (something like this) with an SD card to the breadboard.
We want to use the SD card to log some player data, for instance in the case of snake to store the player name and the score.
When starting a game, a player can choose a name given on some list of pre-set names. (Subject to be changed into an interface, where one can write their name on the LED matrix.) The names will be three letters long.
So we basically have key value pairs, e.g. String name = "lmf" with int score = 62 (...).
We need to be able to
- update the score for a given player name
- sort the list of players by score, such that the highest scores are on top
This involves reading the whole file associated to a game on the SD card, which should be fine since we assume a player list of like 40-50 players.
Now the main questions is, how to efficiently store the data on the SD card such that, reading and writing remains "fast" but also the approach is open to updates. And additionally we can update the score for a given player name and then sort the data by score.
We have so far come up with two ideas:
- using ArduinoJson to define structs and thus store the player data according to this library on the SD card.
- Storing a key value pair as a comma separated line, e.g. lempf,62 (,...) and use string splitting methods to retrieve player name and score.
The first approach would leave the data structures more flexible to future adjustments, whereas the latter idea is probably faster and has less overhead.
Also in the latter case, updating at a specific index and sorting would involve transferring the data into some appropriate data structure (Vector probably) and re-transferring it, before writing back to the SD card.
Does anyone have experience with this kind of problem ? Is it worth using the ArduinoJson library or does it speed down the processes or consume too much memory?
Or does someone maybe have a better idea to store player data (name, score, ...) efficiently on a SD card (including updating and sorting)?
Thanks for the help in advance.
Best regards,
Lempf