BASIC4MCU | 질문게시판 | 답변 : 아두이노 LCD 시계
페이지 정보
작성자 master 작성일2022-06-17 10:33 조회256회 댓글0건본문
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x20,16,2);
#include <stdio.h>
//
char str[30];
int s=0,m=0,h=0,toggle=0,LastBtn=0,NowBtn;
unsigned long t,t1;
//
void setup(){
lcd.init(); lcd.backlight();
}
//
void botton_up(){
if(digitalRead(11)){ if(++h>12)h=0; }
if(digitalRead(10)){ if(++m>59)m=0; }
if(digitalRead( 9)){ if(++s>59)s=0; }
}
//
void botton_down(){
if(digitalRead(11)){ if(--h<0)h=12; }
if(digitalRead(10)){ if(--m<0)m=59; }
if(digitalRead( 9)){ if(--s<0)s=59; }
}
}
//
void loop(){
t=millis();
if(t-t1>=1000){ t1=t;
if(++s>59){ s=0;
if(++m>59){ m=0; if(++h>12)h=0; }
}
sprintf(str,"%02d:%02d:%02d",h,m,s); lcd.setCursor(0,1); lcd.print(str);
//
NowBtn=digitalRead(8);
if(NowBtn==1 && LastBtn==0){ toggle^=1; }
LastBtn=NowBtn;
//
if(toggle)botton_up();
else botton_down();
}
}
댓글 0
조회수 256등록된 댓글이 없습니다.