WorksheetsArduino Quiz #11: Functions
Total questions: 18
Worksheet time: 9mins
What is the main advantage of using functions in an Arduino sketch?
They make the code run faster.
They help organize and modularize the code.
They increase the memory usage.
They make the code harder to read.
Which of the following is a required function in an Arduino sketch?
begin()
initialize()
setup()
main()
What does the 'myMultiplyFunction' do in the example provided?
Adds two numbers
Subtracts two numbers
Multiplies two numbers
Divides two numbers
Where should a custom function be declared in an Arduino sketch?
Inside the setup() function
Inside the main() function
Inside the loop() function
Outside any other function
What is the purpose of the 'ReadSens_and_Condition' function?
To initialize a sensor
To write data to a sensor
To read a sensor, average the readings, scale, and invert the result
To read a sensor and return the raw value
How many times does the 'ReadSens_and_Condition' function read the sensor?
Five times
Four times
Six times
Three times
What is the result of the 'myMultiplyFunction' when called with parameters 2 and 3?
8
5
6
7
What does the 'analogRead(0)' function do in the 'ReadSens_and_Condition' function?
Reads a digital pin
Writes to a digital pin
Writes to an analog pin
Reads an analog pin
What is the purpose of the 'Serial.begin(9600)' line in the setup() function?
To initialize the digital pins
To reset the Arduino
To start the serial communication at 9600 baud rate
To stop the serial communication
What does the 'delay(500)' function do in the loop() function?
Pauses the program for 500 microseconds
Pauses the program for 500 milliseconds
Pauses the program for 500 seconds
Pauses the program indefinitely
What is the role of the 'loop()' function in an Arduino sketch?
To run code once
To stop the program
To run code continuously
To initialize variables
Which function is used to read a digital input in Arduino?
analogWrite()
analogRead()
digitalRead()
digitalWrite()
What is the function of 'pinMode()' in an Arduino sketch?
To write a value to a pin
To read the value of a pin
To delay the program execution
To set a pin as input or output
Which function is used to write a digital output in Arduino?
digitalRead()
analogWrite()
analogRead()
digitalWrite()
What is the purpose of the 'loop()' function in an Arduino sketch?
To initialize variables
To run code continuously
To stop the program
To run code once
What is the purpose of the 'setup()' function in an Arduino sketch?
To initialize variables and settings
To stop the program
To run code continuously
To read sensor data
Which function is used to set the mode of a pin in Arduino?
digitalWrite()
analogRead()
digitalRead()
pinMode()
What does the 'analogWrite()' function do in an Arduino sketch?
Reads a digital pin
Writes a digital value to a pin
Reads an analog pin
Writes an analog value to a pin
