safwan092

explain #1

Apr 4th, 2021
460
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_Fingerprint.h>
  2. int getFingerprintIDez();
  3. // pin #2 is IN from sensor (GREEN wire)
  4. // pin #3 is OUT from arduino  (WHITE wire)
  5. SoftwareSerial mySerial(2, 3);
  6. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   Serial.println("fingertest");
  11.   pinMode(A0, OUTPUT);
  12.   digitalWrite(A0, LOW);
  13.   // set the data rate for the sensor serial port
  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.   }
  21. Serial.println("Waiting for valid finger…");
  22. }
  23. void loop(){
  24.   getFingerprintIDez();
  25.   delay(50);            //don’t ned to run this at full speed.
  26. }
  27. /*uint8_t getFingerprintID() {
  28.   uint8_t p = finger.getImage();
  29.   switch (p) {
  30.     case FINGERPRINT_OK:
  31.       Serial.println("Image taken");
  32.       break;
  33.     case FINGERPRINT_NOFINGER:
  34.       Serial.println("No finger detected");
  35.       return p;
  36.     case FINGERPRINT_PACKETRECIEVEERR:
  37.       Serial.println("Communication error");
  38.       return p;
  39.     case FINGERPRINT_IMAGEFAIL:
  40.       Serial.println("Imaging error");
  41.       return p;
  42.     default:
  43.       Serial.println("Unknown error");
  44.       return p;
  45.   }
  46.   // OK success!
  47.   p = finger.image2Tz();
  48.   switch (p) {
  49.     case FINGERPRINT_OK:
  50.       Serial.println("Image converted");
  51.       break;
  52.     case FINGERPRINT_IMAGEMESS:
  53.       Serial.println("Image too messy");
  54.       return p;
  55.     case FINGERPRINT_PACKETRECIEVEERR:
  56.       Serial.println("Communication error");
  57.       return p;
  58.     case FINGERPRINT_FEATUREFAIL:
  59.       Serial.println("Could not find fingerprint features");
  60.       return p;
  61.     case FINGERPRINT_INVALIDIMAGE:
  62.       Serial.println("Could not find fingerprint features");
  63.       return p;
  64.     default:
  65.       Serial.println("Unknown error");
  66.       return p;
  67.   }
  68.   // OK converted!
  69.   p = finger.fingerFastSearch();
  70.   if (p == FINGERPRINT_OK) {
  71.     Serial.println("Found a print match!");
  72.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  73.     Serial.println("Communication error");
  74.     return p;
  75.   } else if (p == FINGERPRINT_NOTFOUND) {
  76.     Serial.println("Did not find a match");
  77.     return p;
  78.   } else {
  79.     Serial.println("Unknown error");
  80.     return p;
  81.   }
  82.   // found a match!
  83.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  84.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  85. }*/
  86. // returns -1 if failed, otherwise returns ID #
  87. int getFingerprintIDez() {
  88.   uint8_t p = finger.getImage();
  89.   if (p != FINGERPRINT_OK)  return -1;
  90.   p = finger.image2Tz();
  91.   if (p != FINGERPRINT_OK)  return -1;
  92.   p = finger.fingerFastSearch();
  93.   if (p != FINGERPRINT_OK)  return -1;
  94.   // found a match!
  95.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  96.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  97.   digitalWrite(A0, HIGH);
  98.   delay(3000);
  99.   digitalWrite(A0, LOW);
  100.   return finger.fingerID;
  101. }
RAW Paste Data