Loop For Arduino

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

Loop For Arduino
Loop For Arduino

I also develop projects with Arduino

Summary
Loop For Arduino
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
Publisher Name
Drouiz
Publisher Logo

Leave a Reply

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.