I am putting together a project, slowly as I learn, that will need to display text and values in a web page and on an LCD.
I have done quite a bit of reading and playing, listened to a great deal of helpful replies and can now do both.
Thanks all
I want to use similar methods to populate the web page and LCD in so much as I would like to store the hard code in a file that has place-holders for dynamic data.
I have previously asked about this but in a far more general and ill informed manner, see:-
If you are interested.
I now appreciate that to refer to anything at run time the processor uses pointers, which means I will have to do the same.
I have looked at Bitlash, which I am impressed with, but see that it uses predefined variables in EEPROM which I assume is because it need to knlow where they are in order to calculate the pointer required to access them.
There was a suggestion that I map the variables I want to access but not much in the way of detail about how I might go about that.
I suggested using a big case statement in a function to return values based on a text string argument but was advised that mapping was a better way.
SO ...
I know that I must predefine anything that I want to access, which isn't a problem.
I want my place-holders to be human readable and make logical sense so they need to be text strings.
I know I need a function that takes a place-holder as an argument and returns a value.
Given these requirements I can think of 2 ways to go.
-
Use a case statement, there would need to be a case for every variable I want to access.
That seems simple and is probably fast but I doubt its the bast way. -
Use a two arrays one hold the place-holder text and a second, with the same ordinal, to hold a pointer to the value.
I could loop through the first until I found the required name and then get the pointer from the second, using it to return the value.
I appreciate that I would have to 'load' the arrays but would only be doing that once for each variable.
I don't think speed will be a problem so looping through an array of strings isn't going to be an issue but I have no idea how to work with pointers.
I looked about on the web and discovered that * returns a pointer, as opposed to a value, if placed on the left of a variable in an assignment statement.
I couldn't find how to access a value using the pointer, probably because I didn't recognise what I found rather than the info not being available.
How do I go about doing this on an Arduino
a. Getting a pointer to a variable?
b. using the pointer to return the variable value
Do global variables always stay in the same place in memory once they have been created or do I need to do something to ensure that?
Solution 1 is easy, solution 2 isn't - Is there a benefit to using pointers, apart from the learning opportunity, to solve my problem?
Is there anything else I should be looking at?
Sorry that is big, I don't want to make this hard, just right whilst learning whatever I can.
Thanks folks
Al