Components and supplies
Rotary potentiometer (generic)
Jumper wires (generic)
Pushbutton switch 12mm
Resistor 221 ohm
Standard LCD - 16x2 White on Blue
Arduino UNO
Resistor 10k ohm
Project description
Code
untitled
arduino
1 //function: stopwatch with start/stop(button 1) and reset(button 2) 2//start/pause button 1 3//add lap function success!! 4//improve lap function scuuess!! 5 #include<LiquidCrystal.h> 6 LiquidCrystal lcd(12,11,7,6,5,4); 7 8 int ss1 = 0, ss2 = 0; 9 int pss1 = 0; 10 int ms=0,sec =0, minute=0; 11long interval = 98; 12unsigned long last=0,dur,pre=0,last2=0,dur2; 13 int num_rise=0; 14bool reset=0,row=0; 15 16void timeNprint(){ 17 unsigned long curr = millis(); 18 if (curr-pre>interval){ 19 pre=curr; 20 ms++; 21 if (ms==10) {sec++;ms=0;} 22 if (sec==60) {sec=0;minute++;} 23 lcd.setCursor(0,0); 24 if (minute<10) lcd.print("0"); 25 lcd.print(minute); 26 lcd.print(":"); 27 if (sec<10) lcd.print("0"); 28 lcd.print(sec); 29 lcd.print(":"); 30 lcd.print(ms); 31 } 32} 33void printTime(){ 34 lcd.setCursor(9,row); 35 row=!row; 36 if (minute<10) lcd.print("0"); 37 lcd.print(minute); 38 lcd.print(":"); 39 if (sec<10) lcd.print("0"); 40 lcd.print(sec); 41 lcd.print(":"); 42 lcd.print(ms); 43 } 44void resetNwelcome(){ 45 ms=0;minute=0;sec=0; 46 lcd.setCursor(0,1); 47 lcd.print("XW's Stopwatch"); 48 lcd.setCursor(0,0); 49 lcd.print("Welcome to use"); 50} 51 52void setup() { 53lcd.begin(16,2); 54pinMode(2,INPUT); 55pinMode(3,INPUT); 56} 57 58void loop() { 59 num_rise=0; 60 resetNwelcome(); 61 ss1=digitalRead(2); 62if (ss1 == HIGH) 63{ 64 num_rise++; 65 last=millis(); 66 lcd.clear(); 67 while(1) //stop 68 { 69 switch(num_rise%2) 70 { 71 case 0: //pause 72 ss2=digitalRead(3); 73 ss1=digitalRead(2); 74 dur=millis()-last; 75 if (ss2==HIGH) {reset=1;break;} 76 else if(ss1==HIGH && dur>300) { 77 num_rise++; 78 last=millis();} 79 break; 80 case 1: 81 timeNprint(); 82 ss1=digitalRead(2);dur=millis()-last; 83 if (ss1==HIGH &&dur>300) { 84 num_rise++; 85 last=millis(); 86 } 87 break; 88 89 } 90 ss2=digitalRead(3); 91 dur2=millis()-last2; 92 if(ss2==1 && dur2>300) 93 { 94 last2=millis(); 95 printTime(); 96 } 97 if(reset==1) 98 {reset=0;lcd.clear();row=0;break;} 99 } 100} 101}
untitled
arduino
1 //function: stopwatch with start/stop(button 1) and reset(button 2) 2//start/pause 3 button 1 4//add lap function success!! 5//improve lap function scuuess!! 6 7 #include<LiquidCrystal.h> 8 LiquidCrystal lcd(12,11,7,6,5,4); 9 10 int ss1 11 = 0, ss2 = 0; 12 int pss1 = 0; 13 int ms=0,sec =0, minute=0; 14long interval 15 = 98; 16unsigned long last=0,dur,pre=0,last2=0,dur2; 17 int num_rise=0; 18bool 19 reset=0,row=0; 20 21void timeNprint(){ 22 unsigned long curr = millis(); 23 24 if (curr-pre>interval){ 25 pre=curr; 26 ms++; 27 if (ms==10) {sec++;ms=0;} 28 29 if (sec==60) {sec=0;minute++;} 30 lcd.setCursor(0,0); 31 if (minute<10) 32 lcd.print("0"); 33 lcd.print(minute); 34 lcd.print(":"); 35 if (sec<10) 36 lcd.print("0"); 37 lcd.print(sec); 38 lcd.print(":"); 39 lcd.print(ms); 40 41 } 42} 43void printTime(){ 44 lcd.setCursor(9,row); 45 row=!row; 46 if 47 (minute<10) lcd.print("0"); 48 lcd.print(minute); 49 lcd.print(":"); 50 51 if (sec<10) lcd.print("0"); 52 lcd.print(sec); 53 lcd.print(":"); 54 55 lcd.print(ms); 56 } 57void resetNwelcome(){ 58 ms=0;minute=0;sec=0; 59 60 lcd.setCursor(0,1); 61 lcd.print("XW's Stopwatch"); 62 lcd.setCursor(0,0); 63 64 lcd.print("Welcome to use"); 65} 66 67void setup() { 68lcd.begin(16,2); 69pinMode(2,INPUT); 70pinMode(3,INPUT); 71} 72 73void 74 loop() { 75 num_rise=0; 76 resetNwelcome(); 77 ss1=digitalRead(2); 78if (ss1 79 == HIGH) 80{ 81 num_rise++; 82 last=millis(); 83 lcd.clear(); 84 while(1) 85 //stop 86 { 87 switch(num_rise%2) 88 { 89 case 0: //pause 90 91 ss2=digitalRead(3); 92 ss1=digitalRead(2); 93 dur=millis()-last; 94 95 if (ss2==HIGH) {reset=1;break;} 96 else if(ss1==HIGH && dur>300) { 97 98 num_rise++; 99 last=millis();} 100 break; 101 case 1: 102 103 timeNprint(); 104 ss1=digitalRead(2);dur=millis()-last; 105 if 106 (ss1==HIGH &&dur>300) { 107 num_rise++; 108 last=millis(); 109 } 110 111 break; 112 113 } 114 ss2=digitalRead(3); 115 dur2=millis()-last2; 116 117 if(ss2==1 && dur2>300) 118 { 119 last2=millis(); 120 printTime(); 121 122 } 123 if(reset==1) 124 {reset=0;lcd.clear();row=0;break;} 125 } 126} 127}
Downloadable files
untitled
untitled
untitled
untitled
Comments
Only logged in users can leave comments
mingmike
0 Followers
•0 Projects
Table of contents
Intro
7
0