这几天做了一块小板子的计时器
本帖最后由 会五笔的牛 于 2020-10-23 23:04 编辑计时器有3 个按键,
按键1——短按加秒数(加到59再按回零),长按加分数(加到99再按回零).
按键2——短按减秒数(零时按下变59),长按减分数(零时按下变99).
按键3——开始,暂停。
暂停时长按按键2所有数清零 。
这里是代码:
void loop(){
unsigned char timer0=0;
unsigned char timer1=0;
timer2=0;
St_Pa=0;
debouncer0.update();
val0=debouncer0.read();
debouncer1.update();
val1=debouncer1.read();
debouncer2.update();
val2=debouncer2.read();
Display_min_dot(minutes);
Display_sec_dot(adjust_seconds);
if((val0==HIGH)&&(old_val0==LOW)){
for(int r=0;r<106;r++){
Display_min_dot(minutes);
Display_sec_dot(adjust_seconds);
debouncer0.update();
val0=debouncer0.read();
timer0=timer0+val0;
if(val0==0){
r=108;
}
delayMicroseconds(200);
}Serial.print("timer0=");
Serial.println(timer0);
}
old_val0=val0;
if((0<timer0)&&(timer0<49)){
adjust_seconds =++adjust_seconds;
if(adjust_seconds>59){
adjust_seconds = 0;
}
}else if((49<timer0)&&(timer0<105)){
Serial.println(timer0);
minutes=minutes+1;
if(minutes>99){
minutes=0;
}
}else if(timer0>105){
minutes=minutes+10;
if(minutes>99){
minutes=minutes-100;
}
}
if((val1==HIGH)&&(old_val1==LOW)){
for(int r=0;r<106;r++){
Display_min_dot(minutes);
Display_sec_dot(adjust_seconds);
debouncer1.update();
val1=debouncer1.read();
timer1=timer1+val1;
if(val1==0){
r=108;
}
delayMicroseconds(200);
}
}
old_val1=val1;
if((0<timer1)&&(timer1<49)){
adjust_seconds = --adjust_seconds;
if(adjust_seconds<0){
adjust_seconds=59;
}
}else if((49<timer1)&&(timer1<105)){
minutes=minutes-1;
if(minutes<0){
minutes=99;
}
}else if(timer1>105){
minutes=minutes-10;
if(minutes<0){
minutes=100+minutes;
}
}
if((val2==HIGH)&&(old_val2==LOW)){
St_Pa=!St_Pa;
if(adjust_seconds!=0){
for(;adjust_seconds>0;adjust_seconds--){
if(adjust_seconds%2==0){
for(unsigned char b=0;b<109;b++){
Display_min_dot(minutes);
Display_sec_dot(adjust_seconds);
sub_s=adjust_seconds;
sub_m=minutes;
Pause();
}
}else for(unsigned char a=0;a<109;a++){
Display_min(minutes);
Display_sec(adjust_seconds);
sub_s=adjust_seconds;
sub_m=minutes;
Pause();
}
}
if(adjust_seconds<0){
adjust_seconds=0;
}
}
for(;minutes>0;minutes--){
for(unsigned char a=0;a<109;a++){
Display_min_dot(minutes);
Display_sec_dot(0);
}
for(seconds=59;seconds>0;seconds--){
sub_s=seconds;
sub_m=minutes-1;
if(seconds%2 == 0){
for(unsigned char b=0;b<109;b++){
Display_min_dot(sub_m);
Display_sec_dot(sub_s);
Pause();
}
}else for(unsigned char a=0;a<109;a++){
Display_min(sub_m);
Display_sec(sub_s);
Pause();
}
}
}
if(minutes<0){
minutes=0;}
}
}
页:
[1]