Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.40 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #include <Adafruit_Fingerprint.h>
  4.  
  5. /***************************************************
  6. This is an example sketch for our optical Fingerprint sensor
  7.  
  8. Designed specifically to work with the Adafruit BMP085 Breakout
  9. ----> http://www.adafruit.com/products/751
  10.  
  11. These displays use TTL Serial to communicate, 2 pins are required to
  12. interface
  13. Adafruit invests time and resources providing this open source code,
  14. please support Adafruit and open-source hardware by purchasing
  15. products from Adafruit!
  16.  
  17. Written by Limor Fried/Ladyada for Adafruit Industries.
  18. BSD license, all text above must be included in any redistribution
  19. ****************************************************/
  20.  
  21.  
  22.  
  23. #define NUMPIXELS 8
  24. #define PIN 6
  25. Adafruit_NeoPixel Neo = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  26.  
  27. #include <SoftwareSerial.h>
  28. SoftwareSerial mySerial(2, 3);
  29.  
  30. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  31.  
  32. uint8_t id;
  33.  
  34. void setup() //********************************************************************************************************************************************SETUP
  35. {
  36. Serial.begin(9600);
  37. while (!Serial); // For Yun/Leo/Micro/Zero/...
  38. delay(100);
  39. Serial.println("\n\nAdafruit Fingerprint sensor enrollment");
  40.  
  41. // set the data rate for the sensor serial port
  42. finger.begin(57600);
  43.  
  44. if (finger.verifyPassword()) {
  45. Serial.println("Found fingerprint sensor!");
  46. } else {
  47. Serial.println("Did not find fingerprint sensor :(");
  48. while (1) {
  49. delay(1);
  50. }
  51. }
  52. Neo.begin();
  53. pinMode(10, OUTPUT);
  54. pinMode(7, INPUT);
  55.  
  56.  
  57.  
  58. }
  59.  
  60.  
  61. uint8_t readnumber(void) {
  62. uint8_t num = 0;
  63.  
  64. while (num == 0) {
  65. while (! Serial.available());
  66. num = Serial.parseInt();
  67. }
  68. return num;
  69. }
  70.  
  71. boolean alarmArmed = true;
  72. void loop() // *****************************************************************************************************************************************MAIN LOOP
  73. {
  74. Serial.println("Ready to enroll a fingerprint!");
  75. Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  76. id = readnumber();
  77. if (id == 0) {// ID #0 not allowed, try again!
  78. return;
  79. }
  80. Serial.print("Enrolling ID #");
  81. Serial.println(id);
  82.  
  83. while (! getFingerprintEnroll() );
  84.  
  85.  
  86.  
  87. //*************************Alarm Codes Follows**********************
  88. //Begin Alarm OFF
  89. while (alarmArmed == true) {
  90. Neo.show();
  91. if (digitalRead(7) > 0) {
  92. alarmArmed = false;
  93. }
  94. }//End Alarm OFF
  95.  
  96. //Begin Alarm ON
  97. while (alarmArmed == false) {
  98. digitalWrite(10, HIGH);
  99. Neo.setPixelColor(0, 0, 255, 0);
  100. Neo.show();
  101. Neo.setPixelColor(2, 0, 255, 0);
  102. Neo.show();
  103. Neo.setPixelColor(4, 0, 255, 0);
  104. Neo.show();
  105. Neo.setPixelColor(6, 0, 255, 0);
  106. Neo.show();
  107. Neo.setPixelColor(1, 0, 0, 255);
  108. Neo.show();
  109. Neo.setPixelColor(3, 0, 0, 255);
  110. Neo.show();
  111. Neo.setPixelColor(5, 0, 0, 255);
  112. Neo.show();
  113. Neo.setPixelColor(7, 0, 0, 255);
  114. Neo.show();
  115. delay(100);
  116. digitalWrite(10, LOW);
  117. Neo.setPixelColor(0, 0, 0, 255);
  118. Neo.show();
  119. Neo.setPixelColor(2, 0, 0, 255);
  120. Neo.show();
  121. Neo.setPixelColor(4, 0, 0, 255);
  122. Neo.show();
  123. Neo.setPixelColor(6, 0, 0, 255);
  124. Neo.show();
  125. Neo.setPixelColor(1, 0, 255, 0);
  126. Neo.show();
  127. Neo.setPixelColor(3, 0, 255, 0);
  128. Neo.show();
  129. Neo.setPixelColor(5, 0, 255, 0);
  130. Neo.show();
  131. Neo.setPixelColor(7, 0, 255, 0);
  132. Neo.show();
  133. delay(100);
  134.  
  135. }
  136.  
  137. }
  138.  
  139.  
  140.  
  141. //*******************************************************************************Enroll Methods**************************************************
  142.  
  143. uint8_t getFingerprintEnroll() {
  144.  
  145. int p = -1;
  146. Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  147. while (p != FINGERPRINT_OK) {
  148. p = finger.getImage();
  149. switch (p) {
  150. case FINGERPRINT_OK:
  151. Serial.println("Image taken");
  152. break;
  153. case FINGERPRINT_NOFINGER:
  154. Serial.println(".");
  155. break;
  156. case FINGERPRINT_PACKETRECIEVEERR:
  157. Serial.println("Communication error");
  158. break;
  159. case FINGERPRINT_IMAGEFAIL:
  160. Serial.println("Imaging error");
  161. break;
  162. default:
  163. Serial.println("Unknown error");
  164. break;
  165. }
  166. }
  167.  
  168. // OK success!
  169.  
  170. p = finger.image2Tz(1);
  171. switch (p) {
  172. case FINGERPRINT_OK:
  173. Serial.println("Image converted");
  174. break;
  175. case FINGERPRINT_IMAGEMESS:
  176. Serial.println("Image too messy");
  177. return p;
  178. case FINGERPRINT_PACKETRECIEVEERR:
  179. Serial.println("Communication error");
  180. return p;
  181. case FINGERPRINT_FEATUREFAIL:
  182. Serial.println("Could not find fingerprint features");
  183. return p;
  184. case FINGERPRINT_INVALIDIMAGE:
  185. Serial.println("Could not find fingerprint features");
  186. return p;
  187. default:
  188. Serial.println("Unknown error");
  189. return p;
  190. }
  191.  
  192. Serial.println("Remove finger");
  193. delay(2000);
  194. p = 0;
  195. while (p != FINGERPRINT_NOFINGER) {
  196. p = finger.getImage();
  197. }
  198. Serial.print("ID "); Serial.println(id);
  199. p = -1;
  200. Serial.println("Place same finger again");
  201. while (p != FINGERPRINT_OK) {
  202. p = finger.getImage();
  203. switch (p) {
  204. case FINGERPRINT_OK:
  205. Serial.println("Image taken");
  206. break;
  207. case FINGERPRINT_NOFINGER:
  208. Serial.print(".");
  209. break;
  210. case FINGERPRINT_PACKETRECIEVEERR:
  211. Serial.println("Communication error");
  212. break;
  213. case FINGERPRINT_IMAGEFAIL:
  214. Serial.println("Imaging error");
  215. break;
  216. default:
  217. Serial.println("Unknown error");
  218. break;
  219. }
  220. }
  221.  
  222. // OK success!
  223.  
  224. p = finger.image2Tz(2);
  225. switch (p) {
  226. case FINGERPRINT_OK:
  227. Serial.println("Image converted");
  228. break;
  229. case FINGERPRINT_IMAGEMESS:
  230. Serial.println("Image too messy");
  231. return p;
  232. case FINGERPRINT_PACKETRECIEVEERR:
  233. Serial.println("Communication error");
  234. return p;
  235. case FINGERPRINT_FEATUREFAIL:
  236. Serial.println("Could not find fingerprint features");
  237. return p;
  238. case FINGERPRINT_INVALIDIMAGE:
  239. Serial.println("Could not find fingerprint features");
  240. return p;
  241. default:
  242. Serial.println("Unknown error");
  243. return p;
  244. }
  245.  
  246. // OK converted!
  247. Serial.print("Creating model for #"); Serial.println(id);
  248.  
  249. p = finger.createModel();
  250. if (p == FINGERPRINT_OK) {
  251. Serial.println("Prints matched!");
  252. } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  253. Serial.println("Communication error");
  254. return p;
  255. } else if (p == FINGERPRINT_ENROLLMISMATCH) {
  256. Serial.println("Fingerprints did not match");
  257. return p;
  258. } else {
  259. Serial.println("Unknown error");
  260. return p;
  261. }
  262.  
  263. Serial.print("ID "); Serial.println(id);
  264. p = finger.storeModel(id);
  265. if (p == FINGERPRINT_OK) {
  266. Serial.println("Stored!");
  267. } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  268. Serial.println("Communication error");
  269. return p;
  270. } else if (p == FINGERPRINT_BADLOCATION) {
  271. Serial.println("Could not store in that location");
  272. return p;
  273. } else if (p == FINGERPRINT_FLASHERR) {
  274. Serial.println("Error writing to flash");
  275. return p;
  276. } else {
  277. Serial.println("Unknown error");
  278. return p;
  279. }
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement