|
各位大神,请教一下,使用ide编门禁程序时报以下错误,不知道怎么解决了
In file included from /Users/shichaojun/Desktop/Arduino教程/第五步 豪华版传感器教程/11.门禁管理系统/door/door.ino:6:0:
/Users/shichaojun/Documents/Arduino/libraries/DS1302/DS1302.h:51:17: error: expected identifier before numeric constant
#define SUNDAY 7
^
/Users/shichaojun/Documents/Arduino/libraries/DS1302/DS1302.h:51:17: error: expected '}' before numeric constant
/Users/shichaojun/Documents/Arduino/libraries/DS1302/DS1302.h:51:17: error: expected unqualified-id before numeric constant
In file included from /Users/shichaojun/Documents/Arduino/libraries/DS3231/DS3231.h:22:0,
from /Users/shichaojun/Desktop/Arduino教程/第五步 豪华版传感器教程/11.门禁管理系统/door/door.ino:24:
/Users/shichaojun/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include/time.h:506:1: error: expected declaration before '}' token
}
^
In file included from /Users/shichaojun/Desktop/Arduino教程/第五步 豪华版传感器教程/11.门禁管理系统/door/door.ino:22:0:
/Users/shichaojun/Library/Arduino15/packages/arduino/hardware/avr/1.8.4/libraries/EEPROM/src/EEPROM.h:145:20: warning: 'EEPROM' defined but not used [-Wunused-variable]
static EEPROMClass EEPROM;
^~~~~~
********************************************************
以下是全部的代码:
//Arduino C demo
#include <MFRC522.h>
#include <SPI.h>
#include <Servo.h>
#include<LiquidCrystal_I2C.h>
#include<DS1302.h>
LiquidCrystal_I2C lcd(0x27,16,2);
MFRC522 mfrc522(4, UINT8_MAX);
DS1302 rtc(5,6,7);
String readCard;
int beep=13;
bool card;
bool code;
byte year;
byte month;
byte day;
byte dow;
byte hour;
byte minute;
byte second;
#include <Keypad.h>//键盘库
#include <EEPROM.h>//EEPROM库用来保存修改过的密码,掉电后不遗失
#include <Wire.h>
#include <DS3231.h>
RTClib rtc;
const byte ROWS = 4; //3行
const byte COLS = 3; //4列
//键盘位置
char hexaKeys[COLS][ROWS] = {
{'1', '2', '3', '4'},
{'5', '6', '7', '8'},
{'9', '0', '*', '#'}
};
byte rowPins[ROWS] = {10,9,8,7}; //定义接键盘横排引脚
byte colPins[COLS] = {6,5,3}; //竖排引脚定义
//新的键盘对象
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
String oldPassword = "";//保存老密码
String newPassword = "";//保存输入的修改密码
int addNum = 0;//错误计数
String inPut = "";//保存输入字符串
String n = "";//字符串转整型用的变量
byte buzzer=13;//蜂鸣器和板载led
unsigned long now;//现在时间用于计时
unsigned long before;//参考时间用于计时
unsigned long delayTime = 30000;//锁定时间
void setup() {
SPI.begin();
pinMode(beep, OUTPUT);//蜂鸣器引脚
mfrc522.PCD_Init();
mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
pinMode(4, OUTPUT);
lcd.init();
Wire.begin();
lcd.backlight();
digitalWrite(4, 0);
for (int i = 0; i < 4; i++)
{
oldPassword += EEPROM.read(i);
}
delay(2000);
lcd.setCursor(0, 0);//1602输出位置,格式列、行
lcd.print("Please input :");//1602输出
}
void loop() {
readcard();
opendoor();
display();
readtime();
}
void readcard(){
if (getID() != 0) {
if ((readCard)=="4ccaf33") {
card=1;
} else {
servo_8.attach(8);
servo_8.write(90);
for(int i = 0; i < 5; i++){
digitalWrite(4, 1);
delay((0.2) * 1000);
digitalWrite(4, 0);
delay((0.2) * 1000);
card=0;
}
}
}
}
void opendoor(){
if(1&&card==1){
digitalWrite(4,1);
lcd.setCursor(0,0);
lcd.print("Welcome!");
}else{
lcd.clear();
digitalWrite(4,0);
lcd.setCursor(0,0);
lcd.print("Error!");
}
}
void readtime(){
DateTime now=rtc.now();
month=now.month();
day=now.day();
hour=now.hour();
minute=now.minute();
second=now.second();
}
void display(){
lcd.setCursor(0,1);
if(month<10){
lcd.print("0");
}
lcd.print(month);
lcd.print('.');
if(day<10){
lcd.print('0');
}
lcd.print(day);
lcd.setCursor(8,1);
if(hour<10){
lcd.print("0");
}
lcd.print(hour);
lcd.print(':');
if(minute<10){
lcd.print("0");
}
lcd.print(minute);
lcd.print(":");
if(second<10){
lcd.print("0");
}
lcd.print(second);
}
uint8_t getID() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return 0;
}
readCard = String(mfrc522.uid.uidByte[0],HEX)+String(mfrc522.uid.uidByte[1],HEX)+String(mfrc522.uid.uidByte[2],HEX)+String(mfrc522.uid.uidByte[3],HEX);
mfrc522.PICC_HaltA();
return 1;
}
void keypadcode(){
char customKey = customKeypad.getKey();//获取按键
if (customKey)//有按键按下
{
inPut += customKey;//保存输入
lcd.setCursor(i, 1);//在指定位置输出数字
lcd.print(customKey);
//串口打印测试信息
Serial.println("inPut is : ");
Serial.println(inPut);
Serial.println("onece");
i++;//后移1602输出*号位置
if (i > 9)//超过输出位置回归
{
delay(1000);
i = 6;
}
}
//比较密码
if (inPut == oldPassword) //密码正确
{
addNum = 0;//错误次数清零
lcd.clear();//清屏
code=1;
lcd.setCursor(4, 0);//输出位置
lcd.print("Welcome!");//输出welcome
delay(2000);//延时2秒
lcd.clear();//清屏
delay(500);
lcd.setCursor(0, 0); //1列1行
lcd.print("Change Password?");//lcd输出是否修改密码
lcd.setCursor(0, 1);
lcd.print("1.YES 2.NO");//lcd输出1yes2no
int a = 1;
while (a)//等待按键按下
{
customKey = customKeypad.getKey();
if (customKey == '1') //选择1则修改密码
{
a = 0;//跳出while循环
inPut = "";//输入字符串清空
lcd.clear();//LCD清屏
lcd.setCursor(0, 0);//位置
lcd.print("Input the new:");//输出
for (int b = 0; b < 4;)//输入新密码
{
customKey = customKeypad.getKey();
if (customKey)
{
lcd.setCursor(b + 4, 1);
lcd.print(customKey);
newPassword += customKey;
n = customKey;
int num = n.toInt();//将输入的字符转换为整型用toInt()函数
n = "";
//EEPROM保存新密码
EEPROM.write(b, num );
b++;
if (b == 4 )//满足4位
{ newPassword = "";
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);//格式列、行
lcd.print("Save the new !");//lcd输出保存新密码
delay(2000);//延时两秒
oldPassword = "";//清空重置
//读取新密码并设置为当前密码
for (int i = 0; i < 4; i++) {
oldPassword += EEPROM.read(i);
}
lcd.clear();
lcd.setCursor(0, 0);//格式列、行
lcd.print("Please input :");
}
}
}
}
else if (customKey == '2') //选择2什么都不干返回主页
{
a = 0;
inPut = "";//清空输入
lcd.clear();
lcd.setCursor(0, 0);//格式列、行
lcd.print("Please input :");
}
}
}
else if (inPut.length() == 4 && inPut != oldPassword)//密码错误
{
//LCD组合操作清屏,位置,输出信息
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Error!");
code=0;
inPut = "";//清空输入
addNum++;//错误计数+1
//串口打印测试信息
delay(1500);
lcd.clear();
lcd.setCursor(0, 0);//格式列、行
lcd.print("Please input :");
}
if (addNum > 2)//当错到第三次
{
//LCD组合操作
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wait for 30s");
//蜂鸣器报警一秒
digitalWrite(beep, HIGH);
delay(1000);
//计时
before = millis();//参考时间
now = millis();//当前时间
//串口输出测试信息
//锁定键盘等待30秒锁定
while (now - before < delayTime)//当前时间减参考时间小于设定锁定时间
{
lcd.setCursor(0, 0);
lcd.print("Wait for s");
lcd.setCursor(9, 0);
lcd.print((30000 - (now - before)) / 1000);//LCD输出剩余秒数
now = millis();
char key = customKeypad.getKey();
if (key)//如果有按键按下重置时间
{
before = millis();
now = millis();
//串口输出测试信息
}
}
addNum = 0;//锁定时间到,错误次数清零
lcd.clear();
lcd.setCursor(0, 0);//格式列、行
lcd.print("Please input :");
}
}
|
|