Hardware Reference
In-Depth Information
pin
The pin number
value
Either HIGH or LOW (case-sensitive)
Return Value
None.
Example
digitalWrite(9, HIGH);
This turns on pin 9 (sets it to high).
else
Used with the
if
statement, the
else
statement indicates a block of code that
should be executed when
if
evaluates as false. See
“if… else Statements” on
page 74
.
Syntax
if (condition) {
//execute this code if condition is true
}
else {
//execute this code if condition is false
}
Example
int switchInputPin = 2;
void setup() {
pinMode(switchInputPin, INPUT);
Serial.begin(9600);
}
void loop() {
int switchState = digitalRead(switchInputPin);
if (switchState == HIGH) {
Serial.println("The switch is on!");
}
else {
Serial.println("The switch is off!");
}
delay (500);
}