jehankandt
Published © Apache-2.0

Arduino 4 LED Patterns

Arduino 4 LED Patterns using Arrays, digital pins with PWM pins

IntermediateFull instructions provided2,430
Arduino 4 LED Patterns

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
5 mm LED: Red
5 mm LED: Red
×10
Resistor 220 ohm
Resistor 220 ohm
×10
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino 4 LED patterns

Arduino 4 LED patterns

Code

Arduino 4 LED patterns

C/C++
Arduino 4 LED patterns with arrays
int Dpin1 = 2;
int PWM1  = 3;
int Dpin2  = 4;
int PWM2  = 5;
int Dpin3 = 7;
int PWM3  = 6;
int Dpin4 = 8;
int PWM4  = 9;
int Dpin5 = 12;
int PWM5  = 10;


int t = 100;
int led[] = {Dpin1,PWM1,Dpin2,PWM2,Dpin3,PWM3,Dpin4,PWM4,Dpin5,PWM5};
int turn = 10;

void setup() {
  for(int i = 0; i <= 10; i++){
    pinMode(led[i],OUTPUT); 
  }
  
}

void loop() {
   for(int i = 0; i<=turn; i++){
      pat1();
   }
   for(int i = 0; i<=turn; i++){ 
      pat2();
   }
   for(int i = 0; i<=turn; i++){
      pat3();
   }
   for(int i = 0; i<=turn; i++){
      pat4();
   }
}
  
void pat1(){ 
  for(int i = 0; i <= 10; i++){
    digitalWrite(led[i],HIGH);
    delay(t);
    digitalWrite(led[i],LOW);
  }
  for(int i = 10; i >= 0; i--){
    digitalWrite(led[i],HIGH);
    delay(t);
    digitalWrite(led[i],LOW);
  }
}
void pat2(){
  for(int i = 0; i<=10; i=i+2){
    digitalWrite(led[i],HIGH);
    delay(t);
    digitalWrite(led[i],LOW); 
  }
  for(int i = 10; i>=0; i=i-2){
    digitalWrite(led[i],HIGH);
    delay(t);
    digitalWrite(led[i],LOW);
  }
}
void pat3(){
  for(int i = 0; i <= 10; i++){
    digitalWrite(led[i],HIGH);
    delay(t);
  }
  for(int i = 10; i >= 0; i--){
    digitalWrite(led[i],LOW);
    delay(t);
  }
}
void pat4(){
  for(int i = 0; i <= 4; i++){
    digitalWrite(led[i],HIGH);
  }
  delay(500);
  for(int i = 0; i <= 4; i++){
    digitalWrite(led[i],LOW);
  }
  

  
  for(int i = 5; i <= 10; i++){
    digitalWrite(led[i],HIGH);
  }
  delay(500);
  for(int i = 5; i <= 10; i++){
    digitalWrite(led[i],LOW);
  }

}

Credits

jehankandt

jehankandt

21 projects • 8 followers

Comments