Returning multiple values from a method


hello again all.

i need again.

i want return 3 values method calling within code. 3 values dynamically changing- in streaming arduino.

here bit of code 3 values printed serial window


code: [select]

void showdata() {
    if (newdata == true) {

        serial.print(ackdata[0]);
        serial.print(" ");
        serial.print(ackdata[1]);
        serial.print(" ");
        serial.println(ackdata[2]);
        
        newdata = false;
    }
    int setfx   = ackdata [0];
    int lowset  = ackdata [1];
    int highset = ackdata [2];
}



i want 3 values (setfx, lowset, highset)to returned main loop. know void returns nothing , looked @ return method seems single values. nesting returns option? if that's thing.

sorry if terminology way off above programming knowledge @ moment.

i have tried read around forums understand how multiple values or array of values out function bit overwhelmed!

any great, thanks. :)


quote
i want 3 values (setfx, lowset, highset)to returned main loop.
why? local variables copies of elements of global array.

you can not return 3 values function. can pass function 3 addresses want write data. google pass-by-reference.

code: [select]
void uselesscopyfunction(int &uselesscopy1, int &uselesscopy2, int &uselesscopy3)
{
   uselesscopy1 = ackdata[0];
   uselesscopy2 = ackdata[1];
   uselesscopy3 = ackdata[2];
}


Arduino Forum > Using Arduino > Programming Questions > Returning multiple values from a method


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts