Interface 4 push button with arduino & do following: ** SW1 : when press, display 0 to 9 on LCD ** SW2 : when press, display 00 to 99 on LCD ** SW3 : when press, display 000 to 999 on LCD ** SW4 : when press, display 0000 to 9999 on LCD

Here i am using online IDE Tinkercad . If you don't know what is tinkercad then refer my blog HERE or else you can use offline IDE also.

Code :-

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int buttonState1 = 0;

  int buttonState2 = 0;

  int buttonState3 = 0;

  int buttonState4 = 0;


void setup() {

  lcd.begin(16, 2);

  pinMode(6, INPUT);

  pinMode(7, INPUT);

  pinMode(8, INPUT);

  pinMode(9, INPUT);

  Serial.begin(9600);

}


void loop() { 

  if(digitalRead(6)== HIGH){

  for(int i = 0 ; i<=9 ; i++)

  {lcd.setCursor(0,0);

    lcd.print(i);

   delay(500);

  }

  }

 if(digitalRead(7)== HIGH){

  for(int i = 00 ; i<=99 ; i++)

  {lcd.setCursor(0,0);

    lcd.print(i);

   delay(500);

  }

  }  

  if(digitalRead(8)== HIGH){

  for(int i = 000 ; i<=999 ; i++)

  {lcd.setCursor(0,0);

    lcd.print(i);

   delay(500);

  }

  } 

  if(digitalRead(9)== HIGH){

  for(int i = 0000 ; i<=9999 ; i++)

  {lcd.setCursor(0,0);

    lcd.print(i);

   delay(500);

  }

  }

}

Output :-





Comments

Popular Posts

What is Tinkercad ? How to use Tinkercad ?

Connect switch to Arduino. If switch is on than print ”ON” else print “OFF” on serial monitor.

Set the time using four switch and display the clock on LCD using arduino ** SW1 : when press, increment 1 digit ** SW2 : when press, decrement 1 digit ** SW3 : when press, display set time and start the clock ** SW4 : when press, reset the clock