jehankandt
Published © Apache-2.0

LED Patterns change using Push button

LED Patterns change using Push button

IntermediateFull instructions provided2,184
LED Patterns change using Push button

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Pushbutton Switch, Push-Pull
Pushbutton Switch, Push-Pull
×1
5 mm LED: Red
5 mm LED: Red
×10
Resistor 220 ohm
Resistor 220 ohm
×10

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

LED Patterns change using Push button

LED Patterns change using Push button

Code

LED Patterns change using Push button

C/C++
LED Patterns change using Push button
int button = 13;
int t = 100;
int q = 0; 
void setup() {
  for(int i = 2; i <= 11; i++){
    pinMode(i,OUTPUT);
  }
  pinMode(button,INPUT);
}

void loop() {

if(digitalRead(13) == HIGH){
    digitalWrite(2,HIGH);
    delay(t);
  
  }
  if(q == '1'){
    pat1();
  }
  if(q == '2'){
    pat2();
  }
  if(q == '3'){
    pat3();
  }
  if(q == '4'){
    pat4();
  }

}
void pat1(){
  for(int i = 2; i <- 11; i++){
    digitalWrite(i,HIGH);
    delay(t);
    digitalWrite(i,LOW);
  }
  for(int i = 11; i >= 2; i++){
    digitalWrite(i,HIGH);
    delay(t);
    digitalWrite(i,LOW);
  }
}
void pat2(){
  for(int i = 2; i <= 11; i++){
    digitalWrite(i,HIGH);
  }
  delay(1000);
  for(int i = 2; i<= 11; i++){
    digitalWrite(i,LOW);
  }
}
void pat3(){
  for(int i = 2; i <= 6; i++){
    digitalWrite(i,HIGH);
  }
  delay(500);
  for(int i = 7; i <= 11; i++){
    digitalWrite(i,LOW);
  }
  for(int i = 7; i <= 11; i++){
    digitalWrite(i,HIGH);
  }
  delay(500);
  
  for(int i = 9; i <= 13; i++){
    digitalWrite(i,LOW);
  }
}

void pat4(){
  int d = 1;
  for(int a = 2; a<=11; a++){
    digitalWrite(a,HIGH);
    digitalWrite((a - d),HIGH);
    delay(t);

    digitalWrite(a,LOW);
    digitalWrite((a - d),LOW);

    d = d + 2;
  }  
}

Credits

jehankandt

jehankandt

21 projects • 8 followers

Comments