Get a function to update a passed variable?


hi everyone,

i've written little function accepts few inputs.  it works great...except, variables pass function don't have value updated when function runs.

this simplified version of code:
code: [select]
//
// application variables
//

unsigned int intwatertemperature_counter = 0;

//
// application setup
//
void setup() {
 // configure serial output
 serial.begin(9600);

 // start stream carriage return
 serial.println();
}

// application loop
void loop(){

 serial.print(countertest(intwatertemperature_counter));
 serial.print(",");
 serial.println(intwatertemperature_counter);
 delay(500);
}

int countertest(unsigned int thissamplecounter){
 thissamplecounter++;
 return thissamplecounter;
}


the output receive is:
[font=courier]1,0
1,0
1,0
1,0[/font]

i expect receive more like:
[font=courier]1,1
2,2
3,3
4,4[/font]

i know simple, don't understand why doesn't work.  i'm vb dot net programming land!

any appreciated.

cheers,
scott   :o

what assume happening, parameter function countertest, being initialised new variable every execution.  how make function accept existing variable parameter?


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Get a function to update a passed variable?


arduino

Comments