You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
2.3 KiB

5 years ago
/**
* digital clock code for EEE116
*
* @category digital-clock
* @package digital-clock.ino
* @copyright Copyright (c) 2019 IoTcat (https://iotcat.me)
* @license GNU General Public License 2.0
* @version 0.0.1
*/
/*** 引入关键库 ****/
5 years ago
#include "ovo.h"
5 years ago
/*** 是否开启debug模式 ****/
//去掉下一行的注释以开启debug模式
//#define DEBUG_MODE
5 years ago
/*** 定义初始参数 ****/
//小组组号
#define GROUP_ID 22 //计时器增大到此值将重新从零开始
//例如此处我的组号是22
5 years ago
//时钟变换时间间隔 (毫秒)
#define INTERVAL_TIME 1000 //默认是1秒
5 years ago
//pin口 - 接译码器1 (显示个位)
#define DIG_1_1 9 //A
#define DIG_1_2 10 //B
#define DIG_1_3 11 //C
#define DIG_1_4 12 //D
//pin口 - 接译码器2 (显示十位)
#define DIG_2_1 5 //A
#define DIG_2_2 6 //B
#define DIG_2_3 7 //C
#define DIG_2_4 8 //D
//pin口 - 接开关
#define SWI_OFF 3
//pin口 - 接reset键
#define SWI_RESET 4
/*** 引入自定义库 ****/
#include "digital-screen.h"
#include "switch.h"
5 years ago
5 years ago
5 years ago
/*** 运行初始化 ****/
5 years ago
void setup(){
5 years ago
//时钟显示屏初始化
digital_clock_ini();
//开关组件初始化
switch_ini();
5 years ago
//初始化串口,方便debug
Serial.begin(115200);
5 years ago
#ifdef DEBUG_MODE
//初始化板载led,作为debug的指示灯
pinMode(LED_BUILTIN, OUTPUT);
#endif
5 years ago
}
5 years ago
/*** 实例化组件 ****/
5 years ago
#ifdef DEBUG_MODE
//时钟显示屏实例化
Debug_DigitalClock clock(GROUP_ID);
#else
5 years ago
//时钟显示屏实例化
DigitalClock clock(GROUP_ID);
5 years ago
#endif
5 years ago
5 years ago
//开关组件实例化
Switch swi(SWI_OFF), reset(SWI_RESET);
5 years ago
/*** 主循环程序 ****/
5 years ago
void loop(){
5 years ago
/*** 主要控制逻辑 ****/
5 years ago
#ifdef DEBUG_MODE
5 years ago
5 years ago
//如果reset键或开关键被按下,板载led亮
if(reset.isPressed() == true || swi.isPressed() == true) {
digitalWrite(LED_BUILTIN, HIGH);
}else{
digitalWrite(LED_BUILTIN, LOW);
}
#else
5 years ago
//如果reset键被按下,重置时钟
5 years ago
if(reset.isPressed() == true) {
clock.reset();
5 years ago
swi.changeStatus(15);
reset.changeStatus(1);
5 years ago
}
5 years ago
5 years ago
//如果开关打开,则开始或停止计时
5 years ago
if(swi.getStatus() == true) clock.show();
else clock.hide();
5 years ago
#endif
5 years ago
5 years ago
/*** 守护进程 ****/
clock.core();
swi.core();
reset.core();
5 years ago
}