Programming Examples

Arduino program to Increment and Decrement led light using 2 push button




Write a program to interface LEDs at pins 10,11,12,13 and buttons at pins 7,8. When first time button at pin 7(increment button) is pressed first LED at pin 10 is switched on, when second time button is pressed the next LED at 11 is switched on. Similarly, when the button at pin 8 (decrement button) is pressed the LEDs are switched off sequentially.

int count=0;
void setup()
{
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(8, INPUT);
  pinMode(7, INPUT);
}
void loop()
{
  int p1,p2;
  p1=digitalRead(8);// For Increment
  p2=digitalRead(7); // For Decrement
  if(p1==HIGH && count<4)
  {
    count++;
  }
  if(p2==HIGH && count>0)
  {
    count--;
  }
  if(count==0)
  {
 	digitalWrite(13, LOW);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
  	
  }
  else if(count==1)
  {
 	digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
  	
  }
  else if(count==2)
  {
 	digitalWrite(13, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
  	
  }
  else if(count==3)
  {
 	digitalWrite(13, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
  	
  }
  else if(count==4)
  {
 	digitalWrite(13, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
  	
  }
  delay(100); 
  
}
Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad