0
0
Arduinoprogramming~5 mins

Code organization with functions in Arduino - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of using functions in Arduino code?
Functions help organize code into smaller, reusable blocks. This makes the code easier to read, understand, and maintain.
Click to reveal answer
beginner
How do you define a function in Arduino?
You write the return type, function name, parentheses with parameters (if any), and curly braces containing the code. For example:<br>
void blinkLED() {<br>  digitalWrite(LED_BUILTIN, HIGH);<br>  delay(1000);<br>  digitalWrite(LED_BUILTIN, LOW);<br>  delay(1000);<br>}
Click to reveal answer
beginner
What is the difference between 'void' and other return types in function definitions?
'void' means the function does not return any value. Other return types like 'int' or 'float' mean the function sends back a value when it finishes.
Click to reveal answer
beginner
Why is it helpful to call functions inside the loop() function in Arduino?
Calling functions inside loop() keeps the main code clean and easy to follow. It also allows repeating tasks by just calling the function multiple times.
Click to reveal answer
beginner
Can functions in Arduino take inputs? How?
Yes, functions can take inputs called parameters. You put them inside the parentheses when defining the function. For example:<br>
void blinkLED(int delayTime) {<br>  digitalWrite(LED_BUILTIN, HIGH);<br>  delay(delayTime);<br>  digitalWrite(LED_BUILTIN, LOW);<br>  delay(delayTime);<br>}
Click to reveal answer
What keyword is used to define a function that does not return a value in Arduino?
Avoid
Bint
Creturn
Dfunction
Where do you usually call your functions to run repeatedly in an Arduino sketch?
Avoid
Bsetup()
Cmain()
Dloop()
What is the benefit of breaking code into functions?
AOrganizes code into reusable parts
BMakes code longer
CMakes code harder to read
DSlows down the program
How do you pass information to a function in Arduino?
AUsing return statements
BUsing global variables only
CUsing parameters inside parentheses
DUsing comments
Which of these is a correct function call in Arduino?
AblinkLED;
BblinkLED()
Cvoid blinkLED()
DblinkLED{}
Explain how functions help organize Arduino code and give an example of a simple function.
Think about how breaking tasks into small steps makes your code easier to manage.
You got /3 concepts.
    Describe how to pass a value to a function and use it inside the function in Arduino.
    Consider how you tell a friend exactly what to do by giving details.
    You got /3 concepts.