Hardware Reference
In-Depth Information
Syntax
if (condition) {
//execute this code if condition is true
}
Example
int n = 10;
if (n > 10) {
// this will not be executed since n is not greater than 10
digitalWrite(redLed, HIGH);
}
if (n < 10) {
// this will not be executed since n is not less than 10
digitalWrite(greenLed, HIGH);
}
if (n == 10) {
// this will be executed since n equals 10
digitalWrite(yellowLed, HIGH);
}
int
The data type integer. This creates a spot in memory to hold a single whole
number.
Example
int led = 13; // Creates a spot in memory called led and stores
// the number 13 in it.
void setup() {
pinMode(led, OUTPUT); // the value of led (13) is used to
// set the mode.
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
loop
A required function in every Arduino sketch. This is the block of code that's
executed repeatedly after the setup function. See “Setup and Loop” on page
26 .
Search WWH ::




Custom Search