#include "system.h"
LiquidCrystal_I2C lcd (0x27, 20, 4);
RTC_DS1307 rtc;
char hour[5] = {0}; //记录闹钟的“时”
char minute[5] = {0}; //记录闹钟的“分”
char second[5] = {0}; //记录闹钟的“秒”
//用于闹钟的“时”“分”“秒”数据类型转换
int h;
int m;
int s;
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1, A0};
char keys[KEYPAD_ROWS][KEYPAD_COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
int p=0; //判断闹钟设置的状态
int u=0; //记录闹钟设置
int i = 0; //用于循环
int state = 0; //记录是否初次开机
int jud = 0; //用于初次开机输入密码的判断
char Key_Input[10] = {0};
char Key_Set[10] = {"123456"}; //初始密码
unsigned long address1 = 0; //储存密码
unsigned int address2 = 8; //记录是否初次开机
unsigned int address3 = 12; //储存闹钟的“时”
unsigned int address4 = 16; //储存闹钟的“分”
unsigned int address5 = 20; //储存闹钟的“秒”
unsigned int address6 = 24; //储存闹钟设置状态
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
// void eepromGP()
// {
// EEPROM.put(address1, Key_Set);
// EEPROM.put(address2, state);
// }
void showScreen()
{
lcd.setCursor(3, 0);
String message = "input the key";
for (byte i = 0; i < message.length(); i++)
{
lcd.print(message[i]);
delay(50);
}
delay(3000);
lcd.cursor();
lcd.blink();
lcd.setCursor(6, 2);
}
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(7, INPUT_PULLUP);
lcd.init();
lcd.backlight();
showScreen();
if (! rtc.begin())
{
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
Judge_state();//判断是否初次开机
}
void loop()
{
if (state != 0)
{
Check(state); //此时state=2
}
else if (state == 0)
{
Check(state);
}
time();
while (1)
{
DateTime now = rtc.now();
if (now.hour() == 0 && now.minute() == 0 && now.second() == 0)
{
break;
}
time_NF();
int button = digitalRead(7);
if (button == 1 && p==0) //当按钮按下时,进入修改密码的程序
{ //p为0时即未设置闹钟
lcd.clear();
showScreen();
setKey_setclock();
time();
}
Judge_ac();
}
}