Hello,
I am trying to write a program that reports back a specific set of numbers based on todays date. i would like for it to look for todays date and report back the set of four digits next to it.
I would appreciate any help
Thanks
Dan
I am trying to create a standalone arduino with display that looks at the current date and reports back the number in the cell next to it. Currently i have a spreadsheet with the information, this is for a password that we use on our equipment at work that changes daily. The spreadsheet works fine, i would just like make it a little more fun to display the number.
I can extract the spreadsheet into a csv file. or i can manually type into the c code. The dates are in order Decending by date. and currently i would like to have enough to finish out the year so about 100 dates with corresponding code of the day next to each
Thank you to everyone replying
If you are free to select the format of the file then using a binary rather than textual representation will make it easier to read.
If you have one entry per day You could have 4 bytes for the start date and then a series of 2 bytes for the code.
Reading the first 4 bytes will let you know to know when the file starts and calculating the number of days elapsed since that date gives you an offset to jump to the right position in the file (multiplying by the 2 bytes for the code).
So everything is static and you do just one read for the start date, a seek to go to the right position and a read for the 2 bytes for the code. No need to parse and compare which will take a long time if the date is far down the file
Then you read a line into a buffer, extract the date, compare with target date and if it matches then extract the code. If not read next line and rinse and repeat
After having fought with this for several months, please examine you csv file with a dumb display program and ensure it is what you think it is. The current excel program from Microsoft adds a bunch of stuff you don't need.
If you store the data as you did say a char array for the date and a char array for thé code you need 11 bytes for the date and 5 for the code (with trailing null end marker), so 16 bytes per entry.
You have 100 entries so you need 1600 bytes.
Depending on the arduino you use and what the rest of the code needs to do, that might be tough to get that in SRAM of a UNO or Nano for example but it will fit in flash memory though.
Trade off is that you need to modify and recompile the code and upload again when the 100 dates have been used.
Using an SD card is more generic and you basically have no limits and could store easily decades worth of secret codes in one go or just update the file when needed + restart and no code modification is needed for the foreseeable future.
You need to decide how you get the current day’s date (an RTC ? NTP request ?) as well
Presuming you really need the date in every line. I hate storing information that the code can regenerate. Storing the date sequence is equivalent to creating a 2D array just so you can store the row index in the first element of each row. The only reason to store the dates would be if you had a discontinuity in the array, where you skipped days for some reason.
I'd organize it as "starting date" as a separate element, then just the numeric password codes for each date. Any subsequent date is calculable as an index. That reduces the storage to 12 bytes for the date (which could actually be a long unsigned int), and an array of 2*N bytes, where N is the number of days you want to store.
C
Based on my working with a similar file from a spreadsheet, you do not have any fixed length data, so you cannot compute your way to a specific position in the csv file. Serial reading will be the only way.
You could preprocess the csv file and create a file with fixed length fields and store that new file for your searching.