Reading a Button State
Use digitalRead to know if a button is pressed.
Ask the Pin a Question
Now that a pin is listening, you can ask it what it sees. The function digitalRead checks a pin and tells you its current state.
It Returns HIGH or LOW
digitalRead gives back just two answers: HIGH or LOW. That is perfect for a button, which is only ever pressed or not.
int state = digitalRead(2);All lessons in this course
- INPUT vs INPUT_PULLUP
- Reading a Button State
- if/else: LED Follows the Button
- Wire a Button on a Breadboard