EasyManuals Logo

Arduino uno User Guide

Arduino uno
27 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #23 background imageLoading...
Page #23 background image
23
The for statement is used to create program loops. Loops are useful when you want a chunk of
code to be repeated a specified number of times. A variable is used to count the number of times
the code is repeated. Here is an example that flashes an LED attached to pin 2 five times
int i;
void setup()
{
pinMode(2,OUTPUT);
for (i=0;i<5;i++) {
digitalWrite(2,HIGH);
delay(250);
digitalWrite(2,LOW);
delay(250);
}
}
void loop() {}
The variable i is the loop counter. The for() statement has three parts: the initialization, the check
and the increment. Variable i is initialized to zero. The check is to see if i is less then 5. If so, the
commands between the braces are executed. If not, those commands are skipped. After the
check, i is incremented by 1 (the i++ command). While the for statement could read for
(i=1;i==5;i++), it is convention to start the counter variable at zero and use less than for the
condition check.
You can have the loop counter increment by two or by three or by any increment you want. For
example, try this code fragment.
int i;
void setup()
{
Serial.begin(9600);
for (i=0;i<15;i=i+3) {
Serial.println(i);
}
}
void loop() {}
Loops can be nested within loops. This example will flash the LED 10 times because for each of
the five outer loops counted by i, the program goes twice through the inner loop counted by j.
int i,j;
void setup()
{
pinMode(2,OUTPUT);
for (i=0;i<5;i++) {
for(j=0;j<2;j++) {
digitalWrite(2,HIGH);
delay(250);
digitalWrite(2,LOW);
delay(250);
}
}

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals