Recap of Functions

What We’ve Covered So Far

“Calling” or using a function:

“Passing” or giving information to a function:

“Passing” or giving multiple pieces of information to a function:

“Returning” or getting information out of a function:

You need to return data into a variable. You also need to make sure that the variable type matches the type of data you are returning from the function.

“Defining” or writing a function:

You always need a function header and curly brackets to contain the statements inside your function. The parts of the function header are return variable type, function name, parentheses to contain the passed variable types and name, the passed variable(s) type, the passed variable name(s) and if there is more than one passed variable you will also need a comma between the passed variables.

Questions and Activities to Try-

1. Try putting the code that you created to write your name in the array lesson into a function. That should be pretty easy, the tough part is making the function header. It will have a return type of void and no parameters.

2. Now try making a function that returns a character. Any single character you like. Then print that character out onto the LCD like you did in the character lesson. Remember, you’re going to need to create a character type variable as well as creating a function.

Next Step:

Now that you have some idea how functions works, you can use them to operate Sparki. But without being able to make any decisions, it is just preforming actions according to a list. How do we make Sparki intelligent? With Control Statements!

Next Lesson – Controls