Proper way to store and retrieve strings from DAT table?
WBA Consulting
Posts: 2,934
My current project (GPS based Scavenger Hunt) requires a data table that will store 3 pieces of data for 5 items that will be called in groups like in a table sort of like this:
String (clue)
Latitude
Longitude
Maidu Center
38.745843
-121.252334
Location2
38.739822
-121.252056
Location3
38.734363
-121.252490
Location4
38.732386
-121.252764
Last Location
38.736832
-121.252886
I have been laying around with the DAT section code from page 109 of the Propeller Education Kit labs book. However, even though I can store a string with a byte size alignment without issue, I can't figure out how to retrieve just a single string in an array. In other words, if this is my DAT section:
Then how do I pull the second string (clue2) to send to an LCD? All of my attempts to pick one item, just shoot out everything under cluedata; all I can get is "clue1clue2clue3" on the LCD.
Also, how do is store the lat/long? Can I store 38.734363 in a DAT array and have it be usable for my great circle math formulas?
Lastly, if I want the user of my code to have an easy way to modify the code to their clues, latitudes, longitudes, is there a better way than a DAT array?
String (clue)
Latitude
Longitude
Maidu Center
38.745843
-121.252334
Location2
38.739822
-121.252056
Location3
38.734363
-121.252490
Location4
38.732386
-121.252764
Last Location
38.736832
-121.252886
I have been laying around with the DAT section code from page 109 of the Propeller Education Kit labs book. However, even though I can store a string with a byte size alignment without issue, I can't figure out how to retrieve just a single string in an array. In other words, if this is my DAT section:
DAT ClueData byte "clue1", "clue2", "clue3", 0
Then how do I pull the second string (clue2) to send to an LCD? All of my attempts to pick one item, just shoot out everything under cluedata; all I can get is "clue1clue2clue3" on the LCD.
Also, how do is store the lat/long? Can I store 38.734363 in a DAT array and have it be usable for my great circle math formulas?
Lastly, if I want the user of my code to have an easy way to modify the code to their clues, latitudes, longitudes, is there a better way than a DAT array?
Comments
Thanks, that did the trick. I now have tables squared away for the clues, latitudes, and longitudes. Also, since the byte aligned string data will flow out together, I added in some hex codes for the LCD so each clue handles it's own positioning. ( IE: $0c is CLS which positions on the first row, position 0, and $94 is position 0 on the 2nd row). So that I have default lat/longs in the code, I just filled all 5 with Parallax's lat/long. Clue_0 is basically a null because I am using it to determine if it is the first time the unit is powered up so I know whether or not to display instructions.
Here's the DAT table:
And to call out the clues, I am using the following code (EEDATA[2] is the current clue number. I save an array of variables to EEPROM so that powering down doesn't reset you to the first clue):
Thanks to your help, all I have to do now is merge my EEPROM storage/retrieval code, Splash screen code, and my GPS distance measuring code. Since they are all done and working separately, it should be fairly easy from here on out.
Thanks again for the help. Last night I completed the data table section of my code using your suggestions and it works well. I even had time to work on some of the GPS distance math using coordinates from the data table and it worked clean as well. I have a weird issue with the LCD, but I believe I may be missing some delays somewhere in my code. The backlight will flicker once in a while as if I am turning it off/on really quick and a few times it never displayed anything until I reset the prop a second time.
I've had times when I've needed to know this offset to use it other ways.
I believe this offset is always 16 but I'm not sure.
This is how I computed the offset when needed (using your example data).
The method "GetOffset" should return the offset value.
Hoping to have my prototype done soon. I have it completely build (but with a Quickstart and PMB-648 GPS) and my latest version of code is about 90% complete. Just have to figure out a bug with how my code validates when the GPS flags that it has a valid fix and do a few more minor tweaks. I will be buying one of the new VPN1513 GPS modules, product 28510, to make a second unit. The total cost of the project will be under $100 now that the Propeller and GPS is only $35.