// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("Stopwatch");
Serial.begin(9600);
pinMode(5, INPUT); //start
digitalWrite(5, HIGH);
pinMode(4, INPUT); //stop
digitalWrite(2, HIGH);
pinMode(2, INPUT); //lap
}
double i = 0;
double a = millis();
double c ;
void loop() {
// ...
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
if (digitalRead(5) == LOW) //start
{
lcd.clear();
a = millis();
while (digitalRead(4) == HIGH)
{
c = millis();
i = (c - a) / 1000;
lcd.print(i);
lcd.setCursor(7, 0);
lcd.print("Sec's");
lcd.setCursor(0, 0);
Serial.println(c);
Serial.println(a);
Serial.println(i);
Serial.println("......");
delay(100);
}
if (digitalRead(4) == LOW)
{
while (digitalRead(5) == HIGH)
{
lcd.setCursor(0, 0);
lcd.print(i);
lcd.setCursor(11, 0);
lcd.print("");
lcd.setCursor(0, 0);
delay(100);
}
}
}
}