/*********************************************************************
Project: Stopwatch with LCD Display
Author: [Your Name]
Date: [Date]
Description: This Arduino sketch implements a simple stopwatch using
an LCD display and two pushbuttons. One button starts
the stopwatch, and the other button stops it. The elapsed
time is displayed on the LCD.
Components:
- Arduino Uno or similar board
- LiquidCrystal library
- 16x2 LCD display
- 2 pushbuttons
Connections:
- LCD:
- RS (Register Select) pin to Arduino digital pin 7
- Enable pin to Arduino digital pin 6
- D4, D5, D6, D7 pins to Arduino digital pins 5, 4, 3, 2 respectively
- Pushbuttons:
- Start button connected between Arduino digital pin 8 and ground
with a pull-up resistor
- Stop button connected between Arduino digital pin 9 and ground
with a pull-up resistor
- Power:
- Arduino board powered via USB or external power source
Usage:
1. Upload this sketch to the Arduino board.
2. Press the Start button to start the stopwatch. The elapsed time
will be displayed on the LCD.
3. Press the Stop button to pause the stopwatch. The elapsed time
will freeze on the LCD until the Start button is pressed again.
4. Pressing the Start button again will resume the stopwatch from
the point it was paused.
Notes:
- The stopwatch uses the millis() function to measure elapsed time.
- The LCD displays the elapsed time in seconds.
- The stopwatch can be reset by restarting the Arduino or by resetting
the pushbuttons.
References:
- LiquidCrystal library: https://www.arduino.cc/en/Reference/LiquidCrystal
- Arduino millis(): https://www.arduino.cc/reference/en/language/functions/time/millis/
*********************************************************************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup(){
lcd.begin(16, 2);
lcd.clear();
Serial.begin(9600);
pinMode(8, INPUT);
digitalWrite(8, HIGH);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
}
double i = 0;
double a = millis();
double c ;
void loop(){
lcd.clear();
lcd.print("press start");
delay(100);
if(digitalRead(8) == LOW){
lcd.clear();
a = millis();
while(digitalRead(9) == 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(9) == LOW)
{
while(digitalRead(8) == HIGH)
{
lcd.setCursor(0,0);
lcd.print(i);
lcd.setCursor(11,0);
lcd.print("");
lcd.setCursor(0,0);
delay(100);
}
}
}
}