Hello,
I have a function that need to get 6 values, the problem is that this values come from 2 different function.
The problem i struggle that from this 2 function from each i get 3 values,
So my question can i send 3+3 values from this function to the function that get 6 values and if i can how can i do it. Thank you all.
does this help?
void function1(int& a, int& b, int &c)
{
a = 2;
b = 3;
c = 4;
}
void function2(int& a, int& b, int &c)
{
a = 20;
b = 30;
c = 40;
}
void function3(int& a, int& b, int &c, int& d, int& e, int &f)
{
function1(a, b, c);
function2(d, e, f);
}
void setup()
{
int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0;
Serial.begin(115200);
function3(p1, p2, p3, p4, p5, p6);
Serial.print("p1 = "); Serial.println(p1);
Serial.print("p2 = "); Serial.println(p2);
Serial.print("p3 = "); Serial.println(p3);
Serial.print("p4 = "); Serial.println(p4);
Serial.print("p5 = "); Serial.println(p5);
Serial.print("p6 = "); Serial.println(p6);
}
void loop() {}
the & in the functions parameters means that we pass this parameter by reference, so modifying that parameter in the function actually modifies the variable that was used by the caller.
Thank you for reply so quickly. I will try this.
If you know more ways please share, i will always be glad to learn more.
you can use arrays, pointers etc... you need to explain a bit more your need, it's unclear from your first post
and if i have something like this:
void function_1(int& a, int& b, int &c)
{
a = 2;
b = 3;
c = 4;
d=a+b;
e=b+c;
f=a+c;
}
void function_2(int& g, int& h, int &i)
{
g = 20;
h = 30;
i = 40;
j=g+h;
k=h+i;
l=g+i;
}
void function_3(int& d, int& e, int& f,int& j, int& k, int& l){
}
its can be the same to send d,e,f,j,k,l from function 1 and 2 to 3?
sorry if it's a stupid question - but do you understand the difference between local and global variables? (ie variable scope) or passing arguments by value or by reference to a function?
Not really i am learning and try stuff.
OK - so suggest you start there, reading a C or C++ tutorial on variables and functions. Then it will all become much clearer