Greeting everyone. I have been trying different methods for my project for a while and still can't find a solution that works.
I am looking for guidance on how to save the current state of multiple varibles (values represented by numbers) in my program to an SD card.
For example, while my program is running, the values for my variables can be adjusted.
int example = 0; //default for setup
While the program is running I use a button to change the value to my liking
the variable example is now = to 5. // I changed it
Before turning off my controller, I want to be able to hit a button and save the current state of all of my variables to a file on the SD card
Once I power on my controller, it will know to check the SD card and read my file to set all the variables to the previously saved preset.
I understand that I could use EEPROM, but I'd rather use an SD card so that I can simply transfer my presets to any controller running my code and it just works. Also it would give the benifit of others adjusting the varibles on the SD card if wanted, then inserting it into the controller and it reads the file and works.
I even thought of creating a GUI for pc to save presets, but this will limit my project from being about to use those preset on mobile devices. The SD would just handle that in house and not complicate things for other uses.
I even tried using BLYNK. However, when using that app, once you disconnect, then reconnect, all of your settings reset. I think there's a way to prevent it, but again, more apps and downloads and extra things involved that I want to avoid. The SD would incorporate my only needed features, to save and share.
I am using a wio terminal if that helps but I'm assuming it would be a similar process for most boards.
I have tried using the SD library. In the serial monitor, it saves my text file and reads it at the very beginning with the default values, yet this does not save my values later on because it only does it at the beginning. I have tried including the read and write code of the SD library in my loop function, which does update it in the serial monitor, but, once powered off, i am back at square one which defeats the purpose of saving it.
Sorry this all sounds like a lot but I have seen that is possible, but other post that question this topic, when finding the solution, they simply post that they figured it out in the end but their working code isn't included. Understandable, as this give me hope but I am still struggling to find the answer.
Again, my goal is the make a simple program that saves to the SD and is able to recall those settings automatically after being saved (preset).
Program loads sd card and reads,. if it doesn't find anything, it doesn't effect the program. If it finds a previously saved preset file, it loads and updates variables.
Int x = 0; ///// Do some stuff hit buttons that change values...etc
Now
Int x = 25; ///// Hit a button mapped to save my variables to the SD card.
Turn it off, power back on now
Int x = 25;
Thanks in advance for anyone who is willing to help!