You are on page 1of 7

Void and Return Functions with

Arduino
Mr. Michaud
Marist School
Return Type Function
• Takes in Parameters (Most of the time)
• Returns a Value
• Example Use: Math Calculations
• Setup:
int multiply(int a, int b) {
int answer = a * b;
return answer;
}
Other Examples (Note the data types)
Calling Functions
• Create a variable equal to the function
• Print the Variable (or use it in another
calculation . . .)
Exercise
• Take a formula from Science or Math and
write a function to calculate the values.
• Example: F = ma from physics
Void Functions
• Void functions do not return a value.
• Perform a set of actions
– control pin values
– print information to screen
– initialize the board
• void setup()
• void loop()
• Can take Parameters
Example Void Function
String names [] = {"Matthew", "Mark", "Luke", "John"};

void printArray(String a [], int n) {


for (int i = 0; i < n; i++) {
Serial.println(a[i]);
}
}

You might also like