BASIC4MCU | 질문게시판 | 아두이노 스톱워치 코딩 질문
페이지 정보
작성자 master 작성일2018-07-31 12:15 조회13,064회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=2600
본문
#includeconst int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;LiquidCrystal lcd(rs, en, d4, d5, d6, d7);int sec = 0;int min = 0;int hour =0;int counter =0;void setup(){Serial.begin(9600);}void loop(){sec = millis()/1000-60*counter;if(sec ==60) {counter++; min++;}if(min ==60) {min = 0; hour++;}lcd.setCursor(1, 1);lcd.print(hour);lcd.print(" H: ");lcd.print(min);lcd.print(" M: ");lcd.println(sec);lcd.print("s");}이렇게 했는데 왜 이런 식으로 뜨는 건가요?저는 9 s로 뜨게 하려했는데...그리고 버튼으로 정지, 리셋이 되는 스톱워치 형태로는 어떻게 만드나여???//// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-07-20 오전 9:39:20// by Ok-Hyun Park//#include <LiquidCrystal.h>const int rs=12,en=11,d4=5,d5=4,d6=3,d7=2;LiquidCrystal lcd(rs,en,d4,d5,d6,d7);//unsigned int sec=0,min=0,hour=0;unsigned long old_ms=0,ms;char str[21];//void setup(){Serial.begin(9600);}//void loop(){ms=millis();if(ms-old_ms>999){ old_ms=ms;if(++sec==60){ sec=0;if(++min==60){ min=0; if(++hour>23)hour=0; }}sprintf(str,"%02d:%02d:%02d",hour,min,sec);lcd.setCursor(1,1); lcd.print(str);}}
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-07-20 오전 9:50:21// by Ok-Hyun Park//#include <LiquidCrystal.h>const int rs=12,en=11,d4=5,d5=4,d6=3,d7=2;LiquidCrystal lcd(rs,en,d4,d5,d6,d7);//unsigned int sec=0,min=0,hour=0;unsigned long old_ms=0,ms,ms10=0;char run=0,flag=0,str[21];//void setup(){Serial.begin(9600);}//void loop(){if(digitalRead(8)){ run=0; sec=min=hour=0; ms10=0; old_ms=millis(); } // 8번 reset 버튼//if(digitalRead(9)!=flag){ // 9번 start/stop 버튼flag^=1;if(flag)run^=1;delay(50);}//if(run){ms=millis();if(ms-old_ms>9){ old_ms=ms;if(++ms10>99){ ms10=0;if(++sec==60){ sec=0;if(++min==60){ min=0; if(++hour>23)hour=0; }}}sprintf(str,"%02d:%02d:%02d,%02d",hour,min,sec,ms10);lcd.setCursor(1,1); lcd.print(str);}}}
댓글 0
조회수 13,064등록된 댓글이 없습니다.