Grove Beginner Kit For Arduino®
buttonState = digitalRead(buttonPin);
Description:
Reads the value from a specified digital pin, either
Syntax:
digitalRead(pin)
Parameters:
pin: the Arduino
pin
This function is used to read the states of digital pins, either HIGH or LOW. When the button is
pressed, the state is HIGH, otherwise is LOW.
if
(buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
Description:
The if...else allows greater control over the flow of code than the basic if statement, by allowing
multiple tests to be grouped. An else clause (if at all exists) will be executed if the condition in the
if statement results in false. The else can proceed another if test, so that multiple, mutually
exclusive tests can be run at the same time.
Each test will proceed to the next one until a true test is encountered. When a true test is found,
its associated block of code is run, and the program then skips to the line following the entire
if/else construction. If no test proves to be true, the default else block is executed, if one is
present, and sets the default behaviour.
Note that an else if block may be used with or without a terminating else block and vice versa. An
unlimited number of such else if branches are allowed.
number you want to read
or
.
HIGH
LOW
18
Need help?
Do you have a question about the Grove Beginner Kit and is the answer not in the manual?