Contenidos
Introduction to the For loop
The loop FOR is the type of loop more simple, say that is a loop that since is starts know few turns will give (to difference of while that will stop when receive an event). It is declared in the following way:
LOOP FOR ARDUINO
for (initialization, condition, increment)
{
judgments of the loop
}
Usually used to increase one by one and has this form:
for (int i = 0, i < 10, i ++)
Starts with i using 0, whenever just the loop is sum one and is running provided i be less that 10.
Basic code of a for loop for Arduino
Will use a loop for to create an effect of lights turning and turning LEDs from the pin 2 to the 13. The effect will be similar to the of the «Knight Rider» so dedicated to all those who live and grew up in the 1980s.
void setup()
{
for (int i = 2, i < 14, i ++)
{
using the loop to configure the outputs
pinMode(i, OUTPUT);
}
}
void loop()
{
We start in ascending order
for (int i = 2, i < 14, i ++)
{
digitalWrite(i, HIGH);
delay (500);
}
We put out in descending order
for (int i = 13, i > 2, i-)
{
digitalWrite(i, LOW);
delay (500);
}
}
Connection example for For with Arduino
I also develop projects with Arduino
Summary
Article Name
Loop For Arduino
Description
Would you like to learn how to program the Arduino? In this example you will learn how to make a for loop with an example that mimics the fantastic car.
Author
Nuño Valencia
Publisher Name
Drouiz
Publisher Logo