# Retriving data from defined values

How to place data_1 into "text_data" format with those values of data_1
or any other data with same format

#define data_1 30, 40
#define data_2 x4, y4, x5, y5
#define text_data 20, 20, // Location for starting point to display on screen x1, y1
#define rect_data x1, y1, x2, y2 // needs 4 values

the object is to use in following eg:

myGLCD.print("x:", 10, 0, 10, 20); // needs 4 separate parameters in order to work
myGLCD.print("x:", text_data); // (Same as above) where "text_data" contains 2 starting point

What my goal is to retrieve "text_data" into this format x1, y1
which was previously defined and it is used for starting point of
display position on screen

in new case "text_data" in format x1, y1, "text_data" contains 2 starting point and i need "text_data" contains 4 starting point which other 2 can be calculated

and can be changed as this

text data in format x1, y1

x1 = x1 - 3; y1= y1 -3 ;

x2 = x1 + 'display character length' + 3 ; y2 = y1 + 'display character height' + 3 ;

// + 3 is number of pixel above and bellow display

and then draw rectangle around displayed text

myGLCD.drawRect(x1, y1, x2, y2); or
myGLCD.drawRect(rect_data);

myGLCD.print("x:", data_1); // where "data_1" contains 2 starting point with new location/ defined by "data_1"

Hope there is enough information for this problem

That's a lot of description, but it's not very clear. I have the feeling you want to modify a #defined constant, which you can't do. Instead the normal thing to use is variables. If that's not correct, I'm sorry, try to explain (not in more detail, but with more clarity).

#define data_1 30, 40

x1, y2 = (data_1)

Serial.println(x1);
Serial.println(y1);
0
40

not what it should be
30
40

/ ****** Correction to above post ********* /
#define data_1 30, 40

x1, y1 = (data_1) ;

Serial.println(x1);
Serial.println(y1);
0
40

not what it should be
30
40

Look up the comma operator.

Please explain what you are actually trying to do. This does not make much sense:

myGLCD.print("x:", 10, 0, 10, 20); // needs 4 separate parameters in order to work
myGLCD.print("x:", text_data); // (Same as above) where "text_data" contains 2 starting point

See below for my guess, but what is the problem with just putting different numbers into the call arguments?

``````void print2(int i, int j) {
Serial.println(i);
Serial.println(j);
}
void setup() {
Serial.begin(9600);
#define X 10,20
print2(X);
}
void loop() {
}
``````

Pre defined values for display location

eg:
#define clock_position 20, 30
#define temperature_pos 50, 60

then if you need to alter positions just change defined
numbers in one location instead of all over programs.

simple and effective and naming tells you actual what to change
then looking trough whole program.

myGLCD.print("* Text * , 20,30);
or simply
myGLCD.print("* Text * , clock_position);
myGLCD.print("* Text * , temperature_pos);

Same time in program it tells you the name what you are displaying
in case you need to fault find

The example I posted does exactly that.

Your example does work thank you but that would increase program size considerably much bigger and is simply not practical for me.

Would like simpler answer if there is one
something like this

#define data_1 30, 40

int x1,y1

x1, y1 = (data_1) ;

Thank you
Simon

I am not getting why you don't just use const variables to hold the values

then if you need to alter positions just change defined
numbers in one location instead of all over programs.

simple and effective and naming tells you actual what to change
then looking trough whole program.

that would increase program size considerably much bigger.

Nonsense. #define sets up a text substitution, which happens BEFORE the program is compiled.

As suggested above, use constants.

jremington:
#define sets up a text substitution, which happens BEFORE the program is compiled.

That is true**, text substitution**, which happens BEFORE the program is compiled.
Start of any program, then any changes to #defined values would be in one spot, not spanned across multiple pages.

My program is spanned across 20 + pages and would hate to change any values across pages.
Since my program is done by text substitution way, so I can share parts of program to another size of screen.
Original program is written for 800 x 480 size screen.

Then by recalling text substituted values, and change them for screen size 480 x 320 or 320 x 240
Also by using text substitution I can see where one part starts, and easy change for any other location.

Since the only way to retrieve data from text substitution is using Function method mentioned above,
I have successfully adopted to work for me.

Everything you've described can be done better using const variables. What you're missing is aggregate values but that can be done also, using structs:

``````#define   data_1        30, 40
``````

becomes

``````struct  xyVal {
int x;
int y;
}
const xyVal data_1 = {30, 40};
...
xyVal someCoord;
``````

unfortunately, C can't handle lists, so to make a copy you have to

``````someCoord.x = data_1.x;
someCoord.y = data_1.y;
``````

You can create functions that work with those structs, to hide the details so you could for example:

``````setCursorTo(data_1);
``````

What you've done with data_1 will work, but has very limited applications.