-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticateFingerPrint.cpp
114 lines (103 loc) · 2.46 KB
/
authenticateFingerPrint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
A program that determines whether the fingerprint is registered by enrollFingerPrint.
In order to the judgment result explicit, if it is a registered fingerprint, the LED will light up.
*/
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#define FINGERPRINT_RX_PIN 18
#define FINGERPRINT_TX_PIN 19
#define LED_PIN 4
SoftwareSerial fingerSerial(FINGERPRINT_RX_PIN, FINGERPRINT_TX_PIN);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&fingerSerial);
void setup()
{
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(57600);
fingerSerial.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found fingerprint sensor!");
}
else
{
Serial.println("Did not find fingerprint sensor :(");
while (1)
{
delay(1);
}
}
}
void loop()
{
getFingerprintID();
delay(500);
}
void getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return;
default:
Serial.println("Unknown error");
return;
}
p = finger.image2Tz();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return;
default:
Serial.println("Unknown error");
return;
}
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK)
{
Serial.println("Finger found!");
digitalWrite(LED_PIN, HIGH); // LEDを点灯させる処理
delay(2000); // 2秒間LEDを点灯させる
digitalWrite(LED_PIN, LOW); // LEDを消灯させる処理
return;
}
else if (p == FINGERPRINT_PACKETRECIEVEERR)
{
Serial.println("Communication error");
return;
}
else if (p == FINGERPRINT_NOTFOUND)
{
Serial.println("No match found");
return;
}
else
{
Serial.println("Unknown error");
return;
}
}