stopwatch using push buttons

#define sw1 digitalRead(3)
#define sw9 digitalRead(2)

#include<LiquidCrystal.h>

LiquidCrystal lcd(5,6,7,8,9,10);

long i=0,c, j=0,a;

void setup() {
// put your setup code here, to run once:
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(14,INPUT);
pinMode(15,INPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);
pinMode(19,INPUT);

lcd.begin(16,2);
Serial.begin(9600);
lcd.clear();

}

void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,0);
lcd.print(“Stopwatch”);
lcd.print(" ");

lcd.print(“press start”);
delay(100);
lcd.print(" ");

while(sw9==1) // if switch 9 is pressed
{
if(sw1 == 0) //if switch 1 is pressed…to start timer
{
a = millis();
while(sw1==1)
{
c=millis();
i = ((c - a) / 1000);
j = ((c-a)/60000);

lcd.setCursor(7,1);
lcd.print(i);
delay(300);
lcd.print(" “);
lcd.setCursor(3,1);
lcd.print(” : “);
lcd.print(” “);
lcd.setCursor(0,1);
lcd.print(j);
delay(300);
lcd.print(” ");
}
}

}
lcd.setCursor(7,1);
lcd.print(i);
delay(300);
lcd.print(" “);
lcd.setCursor(3,1);
lcd.print(” : “);
lcd.print(” “);
lcd.setCursor(0,1);
lcd.print(j);
delay(300);
lcd.print(” ");

delay(1000);

while(sw9==1)
{
if(sw1 == 0) // to stop timer
{
c = millis();
while(sw1==1)
{
a=millis();
i = ((a - c) / 1000);
j = ((a-c)/60000);

lcd.setCursor(7,1);
lcd.print(i);
delay(300);
lcd.print(" “);
lcd.setCursor(3,1);
lcd.print(” : “);
lcd.print(” “);
lcd.setCursor(0,1);
lcd.print(j);
delay(300);
lcd.print(” ");
}
}

}
lcd.setCursor(7,1);
lcd.print(i);
delay(300);
lcd.print(" “);
lcd.setCursor(3,1);
lcd.print(” : “);
lcd.print(” “);
lcd.setCursor(0,1);
lcd.print(j);
delay(300);
lcd.print(” ");
}

i have to write a program to start a stopwatch when switch 1 is press and then when switch 9 is press then it returns to start a menu again and when switch 1 is pressed again under stopwatch menu then timer gets stops… can anyone guide me ???

I have run the stopwatch, it is running fine but problem is that i m unable to stop a stopwatch. Kindly let me know the corrections which i have to made.

#define sw1 digitalRead(3) // to start and stop a stopwatch
#define sw9 digitalRead(2) // to enter inside a menu

#include<LiquidCrystal.h>

LiquidCrystal lcd(5,6,7,8,9,10);

long i=0,c, j=0,a;

void setup() {
// put your setup code here, to run once:
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(14,INPUT);
pinMode(15,INPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);
pinMode(19,INPUT);

lcd.begin(16,2);
Serial.begin(9600);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:

while(sw9==1)
{
if(sw1==0)
{
while(sw1==1 && sw9 == 1)
{
lcd.setCursor(0, 1);
// print the number of hours since reset:
lcd.print(millis() / 3600000);
lcd.print(“h:”);
// print the number of minutes since reset
lcd.print(millis() / 60000);
lcd.print(“m:”);
// print the number of seconds since reset
lcd.print(millis() / 1000);
lcd.print(“s”);
}
} }

while(sw9==1)
{
if(sw1 ==0)
{
while(sw9==1 && sw1 == 0)
{
// if(sw1==0)
// {
lcd.setCursor(0, 1);
// print the number of hours since reset:
lcd.print(“00”);
lcd.print(" h: “);
// print the number of minutes since reset
lcd.print(“00”);
lcd.print(” m: “);
// print the number of seconds since reset
lcd.print(“00”);
lcd.print(” s: ");
}
}
}
}
}

Here is the code formatted better and in code tags for everyone’s benefit. OP please note

#define sw1 digitalRead(3) // to start and stop a stopwatch
#define sw9 digitalRead(2) // to enter inside a menu

#include<LiquidCrystal.h>

LiquidCrystal lcd(5, 6, 7, 8, 9, 10);

long i = 0, c, j = 0, a;

void setup()
{
  // put your setup code here, to run once:
  pinMode(13, INPUT);
  pinMode(12, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(14, INPUT);
  pinMode(15, INPUT);
  pinMode(16, INPUT);
  pinMode(17, INPUT);
  pinMode(18, INPUT);
  pinMode(19, INPUT);
  lcd.begin(16, 2);
  Serial.begin(9600);
  lcd.clear();
}
void loop()
{
  // put your main code here, to run repeatedly:
  while (sw9 == 1)
  {
    if (sw1 == 0)
    {
      while (sw1 == 1 && sw9 == 1)
      {
        lcd.setCursor(0, 1);
        // print the number of hours since reset:
        lcd.print(millis() / 3600000);
        lcd.print("h:");
        // print the number of minutes since reset
        lcd.print(millis() / 60000);
        lcd.print("m:");
        // print the number of seconds since reset
        lcd.print(millis() / 1000);
        lcd.print("s");
      }
    }
  }
  while (sw9 == 1)
  {
    if (sw1 == 0)
    {
      while (sw9 == 1 && sw1 == 0)
      {
        //  if(sw1==0)
        //  {
        lcd.setCursor(0, 1);
        // print the number of hours since reset:
        lcd.print("00");
        lcd.print(" h: ");
        // print the number of minutes since reset
        lcd.print("00");
        lcd.print(" m: ");
        // print the number of seconds since reset
        lcd.print("00");
        lcd.print(" s: ");
      }
    }
  }
}
}

Note the two closing braces on the margin at then end of the code which prevents it being compiled

#define sw1 digitalRead(3) // to start and stop a stopwatch
#define sw9 digitalRead(2) // to enter inside a menu

I really don’t like this as it makes the code more difficult to read. It would be better in my opinion to give the pins meaningful names and to use explicit digitalRead()s in the code. The names do not even equate to the pin numbers being used.

Why so many pins set to be INPUT then never used ?

Make the current code easier to understand and it will be easier to provide help.