1
2
3
4#include <LiquidCrystal.h>
5
6
7LiquidCrystal lcd(12,11,10,9,8,7);
8
9
10int h=0;
11int m=0;
12int s=0;
13int ms=0;
14
15
16const int startPin = 3;
17const int stopPin = 4;
18const int resetPin = 5;
19
20
21int start=0;
22int stop1=0;
23int reset=0;
24
25
26void stopwatch()
27{
28
29 lcd.setCursor(3,0);
30 lcd.print("TIME:");
31 lcd.print(h);
32 lcd.print(":");
33 lcd.print(m);
34 lcd.print(":");
35 lcd.print(s);
36 lcd.setCursor(3,1);
37 lcd.print(" ");
38
39 ms=ms+10;
40 delay(10);
41
42 if(ms==590)
43 {
44
45 ms=0;
46 s=s+1;
47 }
48
49 if(s==60)
50 {
51 s=0;
52 m=m+1;
53 }
54
55 if(m==60)
56 {
57 m=00;
58 h=h+01;
59 }
60
61
62
63 stop1 = digitalRead(stopPin);
64 if(stop1 == HIGH)
65 {
66 stopwatch_stop();
67 }
68 else
69 {
70 stopwatch();
71 }
72}
73
74void stopwatch_stop()
75{
76 lcd.setCursor(3,0);
77 lcd.print("TIME:");
78 lcd.print(h);
79 lcd.print(":");
80 lcd.print(m);
81 lcd.print(":");
82 lcd.print(s);
83 lcd.setCursor(3,1);
84 lcd.print(" ");
85
86
87 start = digitalRead(startPin);
88 if(start == HIGH)
89 {
90 stopwatch();
91 }
92
93 reset = digitalRead(resetPin);
94 if(reset == HIGH)
95 {
96 stopwatch_reset();
97 loop();
98 }
99 if(reset == LOW)
100 {
101 stopwatch_stop();
102 }
103}
104
105void stopwatch_reset()
106{
107 lcd.clear();
108 h=00;
109 m=00;
110 s=00;
111 return;
112}
113
114
115
116
117void setup()
118{
119
120
121 lcd.begin(16 ,2);
122
123
124 pinMode(startPin, INPUT);
125 pinMode(stopPin, INPUT);
126 pinMode(resetPin, INPUT);
127
128}
129void loop()
130{
131
132 lcd.setCursor(3,1);
133 lcd.print("STOPWATCH");
134 lcd.setCursor(3,0);
135 lcd.print("TIME:");
136 lcd.print(h);
137 lcd.print(":");
138 lcd.print(m);
139 lcd.print(":");
140 lcd.print(s);
141
142 start = digitalRead(startPin);
143 if(start == HIGH)
144 {
145 stopwatch();
146 }
147}
148
149
150
151
152
153
154
155
156
157