Writing Functions
Writing Functions
https://playground.arduino.cc/Code/Function
If code snippets are used repeatedly, it is good coding practice to create user-defined functions using these code snippets.
Void functions do not return a value.
https://playground.arduino.cc/Code/Function
If code snippets are used repeatedly, it is good coding practice to create user-defined functions using these code snippets.
Void functions do not return a value.
Example 1-Void Function :
A void function is one that (1) is not passed values, and (2) does not return a value
Example 2: Non-Void function:
void setup(){
Serial.begin(9600);
}
void loop() {
int i = 2;
int j = 3;
int k;
k = myMultiplyFunction(i, j); // k now contains 6
Serial.println(k);
delay(500);
}
int myMultiplyFunction(int x, int y){
int result;
result = x * y;
return result;
}
// https://www.arduino.cc/en/Reference/FunctionDeclaration
Serial.begin(9600);
}
void loop() {
int i = 2;
int j = 3;
int k;
k = myMultiplyFunction(i, j); // k now contains 6
Serial.println(k);
delay(500);
}
int myMultiplyFunction(int x, int y){
int result;
result = x * y;
return result;
}
// https://www.arduino.cc/en/Reference/FunctionDeclaration
Challenge: Create a program that reads in two values from the serial monitor, and uses them to set the blink rate