Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.41 KB | None | 0 0
  1. /***************************************************
  2.   This is an example sketch for our optical Fingerprint sensor
  3.  
  4.   Designed specifically to work with the Adafruit BMP085 Breakout
  5.   ----> http://www.adafruit.com/products/751
  6.  
  7.   These displays use TTL Serial to communicate, 2 pins are required to
  8.   interface
  9.   Adafruit invests time and resources providing this open source code,
  10.   please support Adafruit and open-source hardware by purchasing
  11.   products from Adafruit!
  12.  
  13.   Written by Limor Fried/Ladyada for Adafruit Industries.  
  14.   BSD license, all text above must be included in any redistribution
  15.  ****************************************************/
  16.  
  17.  
  18. #include <Adafruit_Fingerprint.h>
  19. #include <SoftwareSerial.h>
  20.  
  21. int powerbutton = 4;  //Set to 1 to trigger power button
  22. int powerstatus = 5;  //1 When computer is on, otherwise 0
  23.  
  24. int getFingerprintIDez();
  25.  
  26. // pin #2 is IN from sensor (GREEN wire)
  27. // pin #3 is OUT from arduino  (WHITE wire)
  28. SoftwareSerial mySerial(8, 9);
  29. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  30.  
  31. // On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
  32. //Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);
  33.  
  34. void setup()  
  35. {
  36.   //while (!Serial);  // For Yun/Leo/Micro/Zero/...
  37.  
  38.   pinMode(powerstatus, INPUT);
  39.   pinMode(powerbutton, OUTPUT);
  40.  
  41.   digitalWrite(powerbutton, LOW);
  42.  
  43.   Serial.begin(9600);
  44.   Serial.println("Adafruit finger detect test");
  45.  
  46.   // set the data rate for the sensor serial port
  47.   finger.begin(57600);
  48.  
  49.   if (finger.verifyPassword()) {
  50.     Serial.println("Found fingerprint sensor!");
  51.   } else {
  52.     Serial.println("Did not find fingerprint sensor :(");
  53.     while (1);
  54.   }
  55.   Serial.println("Waiting for valid finger...");
  56. }
  57.  
  58. void loop()                     // run over and over again
  59. {
  60.   int id = getFingerprintIDez();
  61.  
  62.   if (id > -1)
  63.   {
  64.     if (digitalRead(powerstatus) == 0)
  65.     {
  66.         Serial.println("on!");
  67.         digitalWrite(powerbutton, 1);
  68.         delay(250);
  69.         digitalWrite(powerbutton, 0);
  70.     }
  71.     else
  72.     {
  73.       Serial.println("Computer's already on");
  74.     }
  75.   }
  76.  
  77.  
  78.   delay(100);            //don't need to run this at full speed.
  79. }
  80.  
  81. uint8_t getFingerprintID() {
  82.   uint8_t p = finger.getImage();
  83.   switch (p) {
  84.     case FINGERPRINT_OK:
  85.       Serial.println("Image taken");
  86.       break;
  87.     case FINGERPRINT_NOFINGER:
  88.       Serial.println("No finger detected");
  89.       return p;
  90.     case FINGERPRINT_PACKETRECIEVEERR:
  91.       Serial.println("Communication error");
  92.       return p;
  93.     case FINGERPRINT_IMAGEFAIL:
  94.       Serial.println("Imaging error");
  95.       return p;
  96.     default:
  97.       Serial.println("Unknown error");
  98.       return p;
  99.   }
  100.  
  101.   // OK success!
  102.  
  103.   p = finger.image2Tz();
  104.   switch (p) {
  105.     case FINGERPRINT_OK:
  106.       Serial.println("Image converted");
  107.       break;
  108.     case FINGERPRINT_IMAGEMESS:
  109.       Serial.println("Image too messy");
  110.       return p;
  111.     case FINGERPRINT_PACKETRECIEVEERR:
  112.       Serial.println("Communication error");
  113.       return p;
  114.     case FINGERPRINT_FEATUREFAIL:
  115.       Serial.println("Could not find fingerprint features");
  116.       return p;
  117.     case FINGERPRINT_INVALIDIMAGE:
  118.       Serial.println("Could not find fingerprint features");
  119.       return p;
  120.     default:
  121.       Serial.println("Unknown error");
  122.       return p;
  123.   }
  124.  
  125.   // OK converted!
  126.   p = finger.fingerFastSearch();
  127.   if (p == FINGERPRINT_OK) {
  128.     Serial.println("Found a print match!");
  129.   } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  130.     Serial.println("Communication error");
  131.     return p;
  132.   } else if (p == FINGERPRINT_NOTFOUND) {
  133.     Serial.println("Did not find a match");
  134.     return p;
  135.   } else {
  136.     Serial.println("Unknown error");
  137.     return p;
  138.   }  
  139.  
  140.   // found a match!
  141.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  142.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  143. }
  144.  
  145. // returns -1 if failed, otherwise returns ID #
  146. int getFingerprintIDez() {
  147.   uint8_t p = finger.getImage();
  148.   if (p != FINGERPRINT_OK)  return -1;
  149.  
  150.   p = finger.image2Tz();
  151.   if (p != FINGERPRINT_OK)  return -1;
  152.  
  153.   p = finger.fingerFastSearch();
  154.   if (p != FINGERPRINT_OK)  return -1;
  155.  
  156.   // found a match!
  157.   Serial.print("Found ID #"); Serial.print(finger.fingerID);
  158.   Serial.print(" with confidence of "); Serial.println(finger.confidence);
  159.   return finger.fingerID;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement