Stopwatch using switch


#1

#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 ???