Why do we have functions?
A function is a way for programmers to reuse code without having to retype the code.
This is a big time saver, and it makes code more readable, that is if the function names are well selected.
For my example I will use
- returntype = void
- This returntype specifies that the block of code will not return any value. Calling such a function will simply execute all the code in the function body. A return statement is redundant, as a return is implied by the closing curly bracked.
- functionName = FlashLED
- The name describes the action the function does. Running this function will make the LED flash.
- function body
- This is where the code for my function is.
- arguments = no argument, void
returntype functionName( arguments ){ //function body return returntype; }
{ //function body digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); //return returntype; //implied by closing curly bracked }
Leave a Reply