Components and supplies
Tactile Switch, Top Actuated
Arduino Nano R3
Alphanumeric LCD, 16 x 2
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
Jumper wires (generic)
Breadboard (generic)
Resistor 1k ohm
Project description
Code
StopWatch
c_cpp
1/*Simple LCD stopwatch program with stop, start, reset and lap buttons.*/ 2 3//including liblary for LCD 4#include <LiquidCrystal.h> 5 6//setting up LCD INPUT pins 7LiquidCrystal lcd(12,11,10,9,8,7);// (RS,E D4,D5,D6,D7) 8 9//setting hours, minutes, secound and miliseconds to 0 10int h=0; 11int m=0; 12int s=0; 13int ms=0; 14 15//defines pin for all buttons 16const int startPin = 3; 17const int stopPin = 4; 18const int resetPin = 5; 19 20//defines starting points 21int start=0; 22int stop1=0; 23int reset=0; 24 25 26void stopwatch() 27{ 28 29 lcd.setCursor(3,0); //setting start point on lcd 30 lcd.print("TIME:"); //display TIME 31 lcd.print(h); //display hours 32 lcd.print(":"); 33 lcd.print(m); //display minutes 34 lcd.print(":"); 35 lcd.print(s); //display seconds 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) //if state for counting up minutes 50 { 51 s=0; 52 m=m+1; 53 } 54 55 if(m==60) //if state for counting up hours 56 { 57 m=00; 58 h=h+01; 59 } 60 61 62 63 stop1 = digitalRead(stopPin); //reading buton state 64 if(stop1 == HIGH) //checking if button is pressed 65 { 66 stopwatch_stop(); //calls the stopwatch_stop function 67 } 68 else 69 { 70 stopwatch(); //calls the stopwatch function 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); //reading buton state 88 if(start == HIGH) 89 { 90 stopwatch(); //calls the stopwatch function 91 } 92 93 reset = digitalRead(resetPin); //reading buton state 94 if(reset == HIGH) 95 { 96 stopwatch_reset(); //calls the stopwatch_reset function 97 loop(); 98 } 99 if(reset == LOW) 100 { 101 stopwatch_stop(); //calls the stopwatch_stop function 102 } 103} 104 105void stopwatch_reset() 106{ 107 lcd.clear(); 108 h=00; //seting hours to 0 109 m=00; //seting minutes to 0 110 s=00; //seting seconds to 0 111 return; //exiting the program and returning to the point where entered the program 112} 113 114 115 116 117void setup() 118{ 119 120 121 lcd.begin(16 ,2); //starting LCD 122 123 //defining pins if they are INPUT or OUTPUT pins 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); //reading buton state 143 if(start == HIGH) 144 { 145 stopwatch(); //calls the stopwatch function 146 } 147} 148 149 150 151 152 153 154 155 156 157
Comments
Only logged in users can leave comments
nimishac
20 Followers
•3 Projects
2
0