safwan092

اضافة بصمات جديدة 255

Apr 15th, 2021
797
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_Fingerprint.h>
  2. #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
  3. SoftwareSerial mySerial(2, 3);
  4. #else
  5. #define mySerial Serial1
  6. #endif
  7. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  8. uint8_t id;
  9. void setup()
  10. {
  11.   Serial.begin(9600);
  12.   while (!Serial);
  13.   delay(100);
  14.   finger.begin(57600);
  15.   if (finger.verifyPassword()) {
  16.     Serial.println("Found fingerprint sensor!");
  17.   } else {
  18.     Serial.println("Did not find fingerprint sensor :(");
  19.     while (1) {
  20.       delay(1);
  21.     }
  22.   }
  23.   Serial.println(F("Reading sensor parameters"));
  24.   finger.getParameters();
  25.   Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  26.   Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  27.   Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
  28. }
  29. uint8_t readnumber(void) {
  30.   uint8_t num = 0;
  31.   while (num == 0) {
  32.     while (! Serial.available());
  33.     num = Serial.parseInt();
  34.   }
  35.   return num;
  36. }
  37. void loop()
  38. {
  39.   Serial.println("Ready to enroll a fingerprint!");
  40.   Serial.println("Please type in the ID # (from 1 to 255) you want to save this finger as...");
  41.   id = readnumber();
  42.   if (id == 0) {// ID #0 not allowed, try again!
  43.     return;
  44.   }
  45.   Serial.print("Enrolling ID #");
  46.   Serial.println(id);
  47.   while (!  getFingerprintEnroll() );
  48. }
  49. uint8_t getFingerprintEnroll() {
  50.   int p = -1;
  51.   Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  52.   while (p != FINGERPRINT_OK) {
  53.     p = finger.getImage();
  54.     switch (p) {
  55.       case FINGERPRINT_OK:
  56.         Serial.println("Image taken");
  57.         break;
  58.       case FINGERPRINT_NOFINGER:
  59.         Serial.println(".");
  60.         break;
  61.       case FINGERPRINT_PACKETRECIEVEERR:
  62.         Serial.println("Communication error");
  63.         break;
  64.       case FINGERPRINT_IMAGEFAIL:
  65.         Serial.println("Imaging error");
  66.         break;
  67.       default:
  68.         Serial.println("Unknown error");
  69.         break;
  70.     }
  71.   }
  72.   p = finger.image2Tz(1);
  73.   switch (p) {
  74.     case FINGERPRINT_OK:
  75.       Serial.println("Image converted");
  76.       break;
  77.     case FINGERPRINT_IMAGEMESS:
  78.       Serial.println("Image too messy");
  79.       return p;
  80.     case FINGERPRINT_PACKETRECIEVEERR:
  81.       Serial.println("Communication error");
  82.       return p;
  83.     case FINGERPRINT_FEATUREFAIL:
  84.       Serial.println("Could not find fingerprint features");
  85.       return p;
  86.     case FINGERPRINT_INVALIDIMAGE:
  87.       Serial.println("Could not find fingerprint features");
  88.       return p;
  89.     default:
  90.       Serial.println("Unknown error");
  91.       return p;
  92.   }
  93.   Serial.println("Remove finger");
  94.   delay(2000);
  95.   p = 0;
  96.   while (p != FINGERPRINT_NOFINGER) {
  97.     p = finger.getImage();
  98.   }
  99.   Serial.print("ID "); Serial.println(id);
  100.   p = -1;
  101.   Serial.println("Place same finger again");
  102.   while (p != FINGERPRINT_OK) {
  103.     p = finger.getImage();
  104.     switch (p) {
  105.       case FINGERPRINT_OK:
  106.         Serial.println("Image taken");
  107.         break;
  108.       case FINGERPRINT_NOFINGER:
  109.         Serial.print(".");
  110.         break;
  111.       case FINGERPRINT_PACKETRECIEVEERR:
  112.         Serial.println("Communication error");
  113.         break;
  114.       case FINGERPRINT_IMAGEFAIL:
  115.         Serial.println("Imaging error");
  116.         break;
  117.       default:
  118.         Serial.println("Unknown error");
  119.         break;
  120.     }
  121.   }
  122.   p = finger.image2Tz(2);
  123.   switch (p) {
  124.     case FINGERPRINT_OK:
  125.       Serial.println("Image converted");
  126.       break;
  127.     case FINGERPRINT_IMAGEMESS:
  128.       Serial.println("Image too messy");
  129.       return p;
  130.     case FINGERPRINT_PACKETRECIEVEERR:
  131.       Serial.println("Communication error");
  132.       return p;
  133.     case FINGERPRINT_FEATUREFAIL:
  134.       Serial.println("Could not find fingerprint features");
  135.       return p;
  136.     case FINGERPRINT_INVALIDIMAGE:
  137.       Serial.println("Could not find fingerprint features");
  138.       return p;
  139.     default:
  140.       Serial.println("Unknown error");
  141.       return p;
  142.   }
  143.   Serial.print("Creating model for #");  Serial.println(id);
  144.   p = finger.createModel();
  145.   if (p == FINGERPRINT_OK) {
  146.     Serial.println("Prints matched!");
  147.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  148.     Serial.println("Communication error");
  149.     return p;
  150.   } else if (p == FINGERPRINT_ENROLLMISMATCH) {
  151.     Serial.println("Fingerprints did not match");
  152.     return p;
  153.   } else {
  154.     Serial.println("Unknown error");
  155.     return p;
  156.   }
  157.   Serial.print("ID "); Serial.println(id);
  158.   p = finger.storeModel(id);
  159.   if (p == FINGERPRINT_OK) {
  160.     Serial.println("Stored!");
  161.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  162.     Serial.println("Communication error");
  163.     return p;
  164.   } else if (p == FINGERPRINT_BADLOCATION) {
  165.     Serial.println("Could not store in that location");
  166.     return p;
  167.   } else if (p == FINGERPRINT_FLASHERR) {
  168.     Serial.println("Error writing to flash");
  169.     return p;
  170.   } else {
  171.     Serial.println("Unknown error");
  172.     return p;
  173.   }
  174.   return true;
  175. }
  176.  
RAW Paste Data