// 2009 mlab.uiah.fi/paja // Understanding functions int val1Int; int val2Int; void setup(){ Serial.begin(9600); } void loop(){ readSensor1(3); val2Int = readSensor2(4); Serial.print("funcaion readSensor2: "); Serial.print(val2Int); Serial.println(); delay(3000); } void readSensor1(int calib){ // function retun datatype // Void means that the function returns nothing to the function from // which it was called. // Variables in brackets are called arguments. The argments are // the value which is passed from the function from which it was called. // Arguments are regarded as variables, therefore datatype need to be defined. // // an anatomy of function // datatype function(datatype argument, datatype argument, ...){ // statement; // } int x; x = 10 * calib; Serial.print("funcaion readSensor1: "); Serial.print(x); Serial.println(); } int readSensor2(int calib){ // When function is declared with other than void, // the function can return a value to the function from which it was called. // Return indicate the value. The value must be the same datatype as defined // in the function declaration. int x; x = 10 * calib; return x; }