daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Nov 21st, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_Fingerprint.h>
  2. #include <SoftwareSerial.h>
  3. #include <LiquidCrystal.h>
  4. #include <stdlib.h>
  5.  
  6. int getFingerprintIDez();
  7. uint8_t getFingerprintEnroll(uint8_t id);
  8.  
  9.  
  10. SoftwareSerial mySerial(2, 3);
  11. LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
  12.  
  13. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  14.  
  15. void setup()  
  16. {
  17.   Serial.begin(9600);
  18.  
  19.   //pinMode(button, INPUT);
  20.  
  21.   // set the data rate for the sensor serial port
  22.   finger.begin(57600);
  23.  
  24.   if (finger.verifyPassword()) {
  25.     Serial.println("Found fingerprint sensor!");
  26.   delay(50);
  27.   } else {
  28.     Serial.println("Did not find fingerprint sensor :(");
  29.     while (1);
  30.    
  31.   }
  32.   lcd.begin(16,2); lcd.setCursor(0,0); lcd.clear();
  33.   lcd.print("Type in your");
  34.   lcd.setCursor(0,1);
  35.   lcd.print("identity number");
  36. }
  37.  
  38. void loop()                     // run over and over again
  39. {
  40.   types in a number from 0 to 255 in keypad (because of fingerprint memory)
  41.   delay(50);
  42.    int key=0;
  43.    uint8_t test=0;
  44.   while (true) {
  45.     while (! Serial.available());
  46.     char k = Serial.read();
  47.    // if (! isdigit(k)) break;
  48.     key = k - '0';
  49.     Serial.print(k);
  50.   /*  lcd.clear();
  51.     lcd.setCursor(0,0);
  52.     lcd.print("Your identity");
  53.     lcd.setCursor(0,1);
  54.     lcd.print("number is");
  55.     lcd.setCursor(10,1);*/
  56.   }  
  57.  
  58.  if(key == 1)
  59.   {    
  60. Serial.println("Type in the ID # you want to save this finger as...");
  61.  
  62.   uint8_t id = 0;
  63.   while (true) {
  64.     while (! Serial.available());
  65.     char c = Serial.read();
  66.     if (! isdigit(c)) break;
  67.     id *= 10;
  68.     id += c - '0';}
  69.     Serial.println("Enrolling ID #");
  70.     Serial.println(id);
  71.     lcd.clear();
  72.     lcd.print("Enrolling ID #");
  73.     lcd.print(id);
  74.       deleteFingerprint(id);
  75.       delay(100);
  76.   while (!getFingerprintEnroll(id));
  77.   }
  78.   else if(key==3)
  79.   {
  80.     finger.emptyDatabase();
  81.     Serial.print("The database is now cleared");
  82.   }
  83.   else
  84.   {
  85.   delay(2000);
  86.   lcd.clear();
  87.   lcd.print("Scan your finger");
  88.   Serial.println("Waiting for valid finger...");
  89.   lcd.clear();
  90.   lcd.print("Waiting for finger");
  91.   int ret;
  92.   do {
  93.     ret = getFingerprintIDez();
  94.     delay(50);
  95.   }
  96.   while (ret < 0);
  97.   }
  98. }
  99.  
  100.  
  101. //don't ned to run this at full speed.
  102.  
  103.  
  104. uint8_t getFingerprintID() {
  105.   uint8_t n = finger.getImage();
  106.   switch (n) {
  107.     case FINGERPRINT_OK:
  108.    
  109.       Serial.println("Image taken");
  110.      
  111.       break;
  112.     case FINGERPRINT_NOFINGER:
  113.       Serial.println("No finger detected");
  114.       return n;
  115.     case FINGERPRINT_PACKETRECIEVEERR:
  116.       Serial.println("Communication error");
  117.       return n;
  118.     case FINGERPRINT_IMAGEFAIL:
  119.       Serial.println("Imaging error");
  120.       return n;
  121.     default:
  122.       Serial.println("Unknown error");
  123.       return n;
  124.   }
  125.  
  126.   // OK success!
  127.  
  128.   n = finger.image2Tz();
  129.   switch (n) {
  130.     case FINGERPRINT_OK:
  131.       Serial.println("Image converted");
  132.       break;
  133.     case FINGERPRINT_IMAGEMESS:
  134.       Serial.println("Image too messy");
  135.       return n;
  136.     case FINGERPRINT_PACKETRECIEVEERR:
  137.       Serial.println("Communication error");
  138.       return n;
  139.     case FINGERPRINT_FEATUREFAIL:
  140.       Serial.println("Could not find fingerprint features");
  141.       return n;
  142.     case FINGERPRINT_INVALIDIMAGE:
  143.       Serial.println("Could not find fingerprint features");
  144.       return n;
  145.     default:
  146.       Serial.println("Unknown error");
  147.       return n;
  148.   }
  149.  
  150.   // OK converted!
  151.   n = finger.fingerFastSearch();
  152.   if (n == FINGERPRINT_OK) {
  153.    
  154.     Serial.println("Found a print match!");
  155.    
  156.   } else if (n == FINGERPRINT_PACKETRECIEVEERR) {
  157.     Serial.println("Communication error");
  158.     return n;
  159.   } else if (n == FINGERPRINT_NOTFOUND) {
  160.    
  161.  
  162.     Serial.println("Did not find a match");
  163.     return n;
  164.   } else {
  165.     Serial.println("Unknown error");
  166.     return n;
  167.   }  
  168.  
  169.   // found a match!
  170.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  171.   Serial.print(" with confidence of "); Serial.print(finger.confidence);
  172.   lcd.clear();
  173.   lcd.print(finger.fingerID);
  174.  
  175. }
  176.  
  177. // returns -1 if failed, otherwise returns ID #
  178. int getFingerprintIDez() {
  179.  
  180.   uint8_t n = finger.getImage();
  181.   if (n != FINGERPRINT_OK)  return -1;
  182.  
  183.   n = finger.image2Tz();
  184.   if (n != FINGERPRINT_OK)  return -1;
  185.  
  186.   n = finger.fingerFastSearch();
  187.   if (n != FINGERPRINT_OK)  return -1;
  188.  
  189.   // found a match!
  190.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  191.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  192.   lcd.clear();
  193.   lcd.print(finger.fingerID);
  194.   return finger.fingerID;
  195.  
  196.  
  197. }
  198.  
  199. uint8_t getFingerprintEnroll(uint8_t id) {
  200. uint8_t p = -1;
  201.   Serial.println("Waiting for valid finger to enroll");
  202.   while (p != FINGERPRINT_OK) {
  203.     p = finger.getImage();
  204.     switch (p) {
  205.     case FINGERPRINT_OK:
  206.       Serial.println("Image taken");
  207.       break;
  208.     case FINGERPRINT_NOFINGER:
  209.       Serial.println(".");
  210.       break;
  211.     case FINGERPRINT_PACKETRECIEVEERR:
  212.       Serial.println("Communication error");
  213.       break;
  214.     case FINGERPRINT_IMAGEFAIL:
  215.       Serial.println("Imaging error");
  216.       break;
  217.     default:
  218.       Serial.println("Unknown error");
  219.       break;
  220.     }
  221.   }
  222.  
  223.   // OK success!
  224.  
  225.   p = finger.image2Tz(1);
  226.   switch (p) {
  227.     case FINGERPRINT_OK:
  228.       Serial.println("Image converted");
  229.       break;
  230.     case FINGERPRINT_IMAGEMESS:
  231.       Serial.println("Image too messy");
  232.       return p;
  233.     case FINGERPRINT_PACKETRECIEVEERR:
  234.       Serial.println("Communication error");
  235.       return p;
  236.     case FINGERPRINT_FEATUREFAIL:
  237.       Serial.println("Could not find fingerprint features");
  238.       return p;
  239.     case FINGERPRINT_INVALIDIMAGE:
  240.       Serial.println("Could not find fingerprint features");
  241.       return p;
  242.     default:
  243.       Serial.println("Unknown error");
  244.       return p;
  245.   }
  246.  
  247.   Serial.println("Remove finger");
  248.   delay(2000);
  249.   p = 0;
  250.   while (p != FINGERPRINT_NOFINGER) {
  251.     p = finger.getImage();
  252.   }
  253.  
  254.   p = -1;
  255.  
  256.   Serial.println("Place same finger again");
  257.   delay(500);
  258.   while (p != FINGERPRINT_OK) {
  259.     p = finger.getImage();
  260.     switch (p) {
  261.     case FINGERPRINT_OK:
  262.       Serial.println("Image taken");
  263.       break;
  264.     case FINGERPRINT_NOFINGER:
  265.       Serial.print(".");
  266.       break;
  267.     case FINGERPRINT_PACKETRECIEVEERR:
  268.       Serial.println("Communication error");
  269.       break;
  270.     case FINGERPRINT_IMAGEFAIL:
  271.       Serial.println("Imaging error");
  272.       break;
  273.     default:
  274.       Serial.println("Unknown error");
  275.       break;
  276.     }
  277.   }
  278.  
  279.   // OK success!
  280.  
  281.   p = finger.image2Tz(2);
  282.   switch (p) {
  283.     case FINGERPRINT_OK:
  284.    
  285.       Serial.println("Image converted");
  286.       delay(1000);
  287.       break;
  288.     case FINGERPRINT_IMAGEMESS:
  289.       Serial.println("Image too messy");
  290.       return p;
  291.     case FINGERPRINT_PACKETRECIEVEERR:
  292.       Serial.println("Communication error");
  293.       return p;
  294.     case FINGERPRINT_FEATUREFAIL:
  295.       Serial.println("Could not find fingerprint features");
  296.       return p;
  297.     case FINGERPRINT_INVALIDIMAGE:
  298.       Serial.println("Could not find fingerprint features");
  299.       return p;
  300.     default:
  301.       Serial.println("Unknown error");
  302.       return p;
  303.   }
  304.  
  305.  
  306.   // OK converted!
  307.   p = finger.createModel();
  308.   if (p == FINGERPRINT_OK) {
  309.    
  310.     Serial.println("Prints matched!");
  311.     delay(1000);
  312.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  313.     Serial.println("Communication error");
  314.     return p;
  315.   } else if (p == FINGERPRINT_ENROLLMISMATCH) {
  316.     Serial.println("Fingerprints did not match");
  317.     return p;
  318.   } else {
  319.     Serial.println("Unknown error");
  320.     return p;
  321.   }  
  322.   p = finger.storeModel(id);
  323.   if (p == FINGERPRINT_OK) {
  324.    
  325.     Serial.println("Stored!");
  326.     delay(500);
  327.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  328.     Serial.println("Communication error");
  329.     return p;
  330.   } else if (p == FINGERPRINT_BADLOCATION) {
  331.     Serial.println("Could not store in that location");
  332.     return p;
  333.   } else if (p == FINGERPRINT_FLASHERR) {
  334.     Serial.println("Error writing to flash");
  335.     return p;
  336.   } else {
  337.     Serial.println("Unknown error");
  338.     return p;
  339.   }
  340. }  
  341.   uint8_t deleteFingerprint(uint8_t id) {
  342.   uint8_t p = -1;
  343.  
  344.   p = finger.deleteModel(id);
  345. }
RAW Paste Data
Top