uint8_t enrollFingerprint(uint8_t id) {
int p = -1;
Serial.print("Waiting for finger to enroll...");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Error receiving packet");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
}
// Convert and store the image template
p = finger.image2Tz(1);
if (p != FINGERPRINT_OK) return p;
p = finger.storeModel(id);
if (p == FINGERPRINT_OK)
Serial.println("Fingerprint enrolled!");
else
Serial.println("Failed to store fingerprint.");
return p;
}
void setup() {
Serial.begin(115200);
mySerial.begin(57600, SERIAL_8N1, 16, 17);
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Sensor initialized.");
enrollFingerprint(1); // Enroll the first fingerprint
}
}