The series of four LED Arduino Update

Please update your Arduino circuit such as a string at the top. Prepare four resistors and four LEDs. Prepare a jumper cable to supply the GDN on the project board. Each LED negative leg is connected to GND with a resistor. While four LEDs are connected in a row with a pin 8, 9, 10, and 11 on the Arduino board.

The series of Four LED


If you do not have a lot of resistors to try, then you can menggukaan 1 resistors only with the circuit as circuit below, but with consequences: current supply will be shared so that the LED flame will increasingly dim (or maybe the LED would not light up, depending on LED you use).

If already assembled, please upload Sketch 1 below:


// www.ioisalman.com  
// Initialization Pin LEDs 

const int pinLED1 = 8; 
const int pinLED2 = 9; 
const int pinLED3 = 10; 
const int pinLED4 = 11;  
void setup() {     
// LED pin as an output     
pinMode(pinLED1, OUTPUT);     
pinMode(pinLED2, OUTPUT);    
pinMode(pinLED3, OUTPUT);     
pinMode(pinLED4, OUTPUT); } 
 
void loop() {   
// Looping 5 times
// From i = 0 to i = 4 or (i <5)
  
for(int i=0; i<5; i++)
{     
if(i==1){       
// if i = 1, turn led 1, led the others are dead  
digitalWrite(pinLED1, HIGH);       
digitalWrite(pinLED2, LOW);       
digitalWrite(pinLED3, LOW);       
digitalWrite(pinLED4, LOW);     
}
else if(i==2){       
// if i = 2, turn led 1 & 2, 3 & 4 led to death       
digitalWrite(pinLED1, HIGH);       
digitalWrite(pinLED2, HIGH);       
digitalWrite(pinLED3, LOW);       
digitalWrite(pinLED4, LOW);     }
else if(i==3){       
// if i = 3, turn on the LED 1, 2, & 3, led 4 dead
digitalWrite(pinLED1, HIGH);       
digitalWrite(pinLED2, HIGH);       
digitalWrite(pinLED3, HIGH);       
digitalWrite(pinLED4, LOW);     }
else if(i==4){       
// if i = 4, turn all LED       
digitalWrite(pinLED1, HIGH);       
digitalWrite(pinLED2, HIGH);       
digitalWrite(pinLED3, HIGH);       
digitalWrite(pinLED4, HIGH);     
}else
{       
// if not, turn off all LED       
digitalWrite(pinLED1, LOW);       
digitalWrite(pinLED2, LOW);       
digitalWrite(pinLED3, LOW);       
digitalWrite(pinLED4, LOW);     
}     
// delay for 5 seconds    
 delay(5000);   
} 
} 

The above program will make the LED light up alternately by 5 animation (looping 5 times). First, all LED turns off for 5 seconds. Second, LED 1 will light. Third, LED 1 and 2 will light up. Fourth, LED 1, 2, and 3 will turn on. Fifth, all the LEDs will light up.

The animation is determined based on the value of i, i checked with the command value IF. If the value of i = 0, then all the LED die, if i = 1 then a single LED flash, and so on.
In addition to using the IF, there is another more simple way to create animated LED as a program on the Sketch 1. Sketch note 2:

// www.ioisalman.com  
// Initialization Pin LEDs 

const int pinLED1 = 8; 
const int pinLED2 = 9; 
const int pinLED3 = 10; 
const int pinLED4 = 11;  
void setup() {     
// LED pin as an output     
pinMode(pinLED1, OUTPUT);     
pinMode(pinLED2, OUTPUT);    
pinMode(pinLED3, OUTPUT);     
pinMode(pinLED4, OUTPUT); } 
 
 void loop() {   
digitalWrite(pinLED1, LOW);   
digitalWrite(pinLED2, LOW);   
digitalWrite(pinLED3, LOW);   
digitalWrite(pinLED4, LOW);   
delay(1000);   
digitalWrite(pinLED1, HIGH);   
delay(1000);   
digitalWrite(pinLED2, HIGH);   
delay(1000);   
digitalWrite(pinLED3, HIGH);   
delay(1000);   
digitalWrite(pinLED4, HIGH);   
delay(1000); 
} 


By utilizing the delay, the program is more simple than the Sketch 2 Sketch 1. Approximately, is there a more simple way anymore? There is! We can use the Array. What's Array?

Subscribe to receive free email updates:

0 Response to "The series of four LED Arduino Update"

Post a Comment