Which is the correct syntax to configure a digital pin (D2) as an OUTPUT?

Study for the Internet of Things (IOT102) Test. Access comprehensive flashcards and multiple choice questions, each with hints and explanations. Get prepared for your exam!

Multiple Choice

Which is the correct syntax to configure a digital pin (D2) as an OUTPUT?

Explanation:
The key idea is that configuring a digital pin uses a function with two parts: the pin number and the mode. The pin number identifies which pin you’re treating, here the numeric 2 corresponds to digital pin 2. The mode must be one of the predefined constants, and it must be written exactly as the environment defines it, in uppercase. So the correct call is pinMode(2, OUTPUT); using OUTPUT in uppercase matches the defined constant that tells the core to treat the pin as an output. Using a lowercase function name like pinmode, a lowercase mode like output, or any other capitalization won’t match the defined identifiers and won’t compile. Remember that D2 in code is represented by the numeric 2, and once you set pin 2 to OUTPUT you can drive it HIGH or LOW with digitalWrite.

The key idea is that configuring a digital pin uses a function with two parts: the pin number and the mode. The pin number identifies which pin you’re treating, here the numeric 2 corresponds to digital pin 2. The mode must be one of the predefined constants, and it must be written exactly as the environment defines it, in uppercase. So the correct call is pinMode(2, OUTPUT); using OUTPUT in uppercase matches the defined constant that tells the core to treat the pin as an output. Using a lowercase function name like pinmode, a lowercase mode like output, or any other capitalization won’t match the defined identifiers and won’t compile. Remember that D2 in code is represented by the numeric 2, and once you set pin 2 to OUTPUT you can drive it HIGH or LOW with digitalWrite.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy