Podcast
Questions and Answers
We define a constant for the digital output pin as 'const int pin_o = ______;'
We define a constant for the digital output pin as 'const int pin_o = ______;'
13
The variable 'State' is used to store the state of the ______.
The variable 'State' is used to store the state of the ______.
input
To set pin 13 as an output, the function used is 'pinMode(pin_o, ______);'.
To set pin 13 as an output, the function used is 'pinMode(pin_o, ______);'.
OUTPUT
The function 'digitalRead(pin_i)' reads the pin state and assigns it to the ______.
The function 'digitalRead(pin_i)' reads the pin state and assigns it to the ______.
Signup and view all the answers
When the button is pressed, 'digitalWrite(pin_o, ______);' turns the LED on.
When the button is pressed, 'digitalWrite(pin_o, ______);' turns the LED on.
Signup and view all the answers
Study Notes
Digital I/O Code Example
- The code defines two integer constants:
pin_o
for the output pin (13) andpin_i
for the input pin (1). - The
State
variable will store the state of the input (pushbutton). - The
setup()
function is executed once and configures the pins:-
pinMode(pin_o,OUTPUT)
sets pin 13 as an output. -
pinMode(pin_i,INPUT)
sets pin 1 as an input.
-
- The
loop()
function is executed repeatedly:-
State = digitalRead(pin_i)
reads the value of pin 1 and assigns it to theState
variable. - The
if
statement checks if theState
is 1 (button pressed) and then:-
digitalWrite(pin_o,HIGH)
sets the output pin (13) to a high level, turning the LED on.
-
- The
else
statement executes if the button is not pressed:-
digitalWrite(pin_o,LOW)
sets the output pin (13) to a low level, turning the LED off.
-
-
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Explore the basics of Digital Input/Output in Arduino with this code example. This quiz covers the configuration of input and output pins and how to read and control states. Test your understanding of how to use the setup()
and loop()
functions effectively.