Using functions

Hello. I'm new to Arduino.

Can anyone tell me how to use functions when a variable is to be passed to a function, but no variable is required to be returned. I assumed that you would use void (variable name); at the beginning of the function, but that just results in a heap of errors. Could someone show me an example, so I know the syntax? The program itself works fine with the code just lined up, but I want to break it up into functions.

I hope someone can help me.

Stuart

To create a function like that:

void functionName (int variable) {
   Serial.println(variable); // function code
}

To call that function:

int someVariable = 10;
functionName(someVariable);
3 Likes

Thank you very much Hutkikz. I've tried that form, and it works perfectly!

Thank you again.

1 Like

Hello duodiode

Take a view here to gain the knowledge:

https://www.learncpp.com/cpp-tutorial/introduction-to-functions/

1 Like

Thank you Paul and all others for your help. I'm learning!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.