Simple question of parameter

Hi arduino~
I have very simple question but nowhere to ask

If i make a function like

void hello()
{
   something is here
}

something like this!
main question is this

If I have parameter made in loop
that parameter must be local parameter and cannot be used at hello()
then! we have to declare parameter as global parameter
but this parameter should change consistently as sensor received

How can I use the value from loop at other function?
please help me

Hello,

Make 'value' a parameter of the function

http://www.cplusplus.com/doc/tutorial/functions/

It is perfectly practical to use a global variable - the fact that it changes regularly does not matter if it meets your need.

The alternative is to pass a parameter to your function - something like

void hello( int myValue) {
  // use myValue within the function
}
void loop() {
  int someValue = 23;
  hello(someValue);
}

but if you do it like that the actions taken within hello() won't be accessible in loop() unless you extend the function hello() so that it returns a result.

...R

Robin2:

void hello( int myValue) {

// use myValue within the function
}





void loop() {
  int someValue = 23;
  hello(someValue);
}



but if you do it like that the actions taken within hello() won't be accessible in loop() unless you extend the function hello() so that it returns a result.

Or make the function take a pointer and pass the pointer to the variable :wink:

sterretje:
Or make the function take a pointer and pass the pointer to the variable :wink:

You need oxygen when you get that far up the learning curve :slight_smile:

...R

sterretje:
Or make the function take a pointer and pass the pointer to the variable :wink:

ah pointer! that could be helpful

I didn't even recognize that is in arduino lol thx for help

Robin2:
It is perfectly practical to use a global variable - the fact that it changes regularly does not matter if it meets your need.

The alternative is to pass a parameter to your function - something like

void hello( int myValue) {

// use myValue within the function
}





void loop() {
 int someValue = 23;
 hello(someValue);
}



but if you do it like that the actions taken within hello() won't be accessible in loop() unless you extend the function hello() so that it returns a result.

...R

ah~use like that

thx for your advice!