Digital I/O Code Example in Arduino
5 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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 ______.

input

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 ______.

<p>State</p> Signup and view all the answers

When the button is pressed, 'digitalWrite(pin_o, ______);' turns the LED on.

<p>HIGH</p> 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) and pin_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 the State variable.
    • The if statement checks if the State 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.

Quiz Team

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.

More Like This

Arduino Programming and Code Comments Quiz
10 questions
Arduino Uno Board Quiz
10 questions
Common Arduino Code Concepts
32 questions
Use Quizgecko on...
Browser
Browser