Many Electronic circuit projects in simple ways of learning

# 3 LED running-int code by Arduino

This is the easy 3 LED running circuit or LED Chaser using Arduino. We will learn code “int” to define the variable.
-variable Is representatives of the various

Let’s write code Sample one LED flasher. Which we’ve already made easiest it

——code Sample one LED flasher use int on Arduino

```int pin1 = 13;   // to define the variable

void setup()
{
pinMode (pin1, OUTPUT);  // pin1 = 13
}
void loop()
{
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
delay (1000);
}
```

++++++++++++

From the code above. We use “int” to define the variable: pin1 = 13
The number 13 is output of arduino use for LED

In void setup() we set pinMode(pin1, OUTPUT) Which pin1 is 13.

Summarize : To see that we can use the command “int” To determine the variables To represent the various Easier to understand.

Lets builds the 3 LED Running

Next, we try to make the 3 LED Running using Arduino as Figure 1 and Figure 2 is circuit connection Then, next, let’s write the code 3 LED Running without int on Arduino
–—code—-

```  void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

}

void loop() {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
delay(1000);
}
```

We will see that, although the short code. If you want to change pin output 13,12,11 into others pins (for example 10,9,8). It must to change several points so inconvenient. Or code: delay (1000) To change the time delay is 100 (0.1S) or p2000 (2S) will be edited together three positions. If our code long, it is very difficult to edit.

The 3 LED Running with int on Arduino

From the these problems, let’s use an int as well.
int red = 13; => for the red LED pin have variable is “red”.
int green = 12; => for the green LED pin have variable is “green”
int yellow = 11; => for the yellow LED pin have variable is “yellow”
int delay1 = 1000; => for times value have variable is “delay1”

—-code—-

```int red = 13;
int green = 12;
int yellow = 11;
int delay1 = 1000;

void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);

}

void loop() {
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
delay(delay1);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(yellow, LOW);
delay(delay1);
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(delay1);
}```

We try to test this code is OK! Done complier and Good upload.

As Video below.

We edit delay time easily! If you do not understand the programming. Please read back. Sample one LED flasher and Blink 2 LED flasher using Arduino Yes You Can!

### Related Posts

JLCPCB - Only \$2 for PCB Protytpe(Any Color)

With 600,000+ Customers Worldwide, 10,000+ PCB Orders Per Day

Up to \$20 shipping discount on first order now: https://jlcpcb.com/quote