Advertisement
safwan092

Project_9876_Skeleton_code

Sep 14th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. #include <Adafruit_Fingerprint.h>
  2.  
  3. #define mySerial Serial2
  4. #define RXD2 16
  5. #define TXD2 17
  6. #define btn 4
  7.  
  8. int totalCountCalculated = 0;
  9. int numberOfStudents = 4;
  10. int totalCount = numberOfStudents;
  11. int StudentNumber[numberOfStudents] = 0; // 1 2 3 4
  12. int ParentNumber[numberOfStudents] = 0; // 1 2 3 4
  13. //**************************************************************
  14. int ParentTelegramID[numberOfStudents];//Must Set!!!!!!
  15. //**************************************************************
  16.  
  17. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  18.  
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22. pinMode(btn, INPUT);
  23. initFingerPrint();
  24. resetData();
  25. }
  26.  
  27. void loop() {
  28. /////////////////////////////////////////////////////////////////
  29. //Handle Messages from Parents Telegram
  30.  
  31. //Parent of Child #1
  32. //ParentNumber[0]=1
  33. //totalCount = totalCount - ParentNumber[0]
  34.  
  35. //Parent of Child #2
  36. //ParentNumber[1]=1
  37. //totalCount = totalCount - ParentNumber[1]
  38.  
  39. //Parent of Child #3
  40. //ParentNumber[2]=1
  41. //totalCount = totalCount - ParentNumber[2]
  42.  
  43. //Parent of Child #4
  44. //ParentNumber[3]=1
  45. //totalCount = totalCount - ParentNumber[3]
  46. /////////////////////////////////////////////////////////////////
  47.  
  48. if (digitalRead(btn) == 1) {
  49. if (totalCountCalculated != totalCount) {
  50. //Send Alert To Driver
  51. for (int i = 0; i < numberOfStudents; i++) {
  52. if (ParentNumber[i] == 0 && StudentNumber[i] == 0) {
  53. //Send Message to Parent of Child #(i+1) Child did not enter the bus Alert!!
  54. //Send Message to Driver Child #(i+1) did not enter the bus Alert!! and Parents did not pick up
  55. }
  56. }
  57. }
  58. }
  59. if (getFingerprintIDez() != -1) {
  60.  
  61. /////////////////////////////////////////////////
  62. if (StudentNumber[getFingerprintIDez() - 1] == 1) {
  63. StudentNumber[getFingerprintIDez() - 1] = 0;
  64. totalCountCalculated = totalCountCalculated - 1;
  65. //Send Message to Parent Child is OUT of the Bus
  66. //Send Message to Driver totalCountCalculated/TotalCount
  67. }
  68. else {
  69. StudentNumber[getFingerprintIDez() - 1] = 1;
  70. totalCountCalculated = totalCountCalculated + 1;
  71. //Send Message to Parent Child is IN the Bus
  72. //Send Message to Driver Child is IN the Bus
  73. //Send Message to Driver totalCountCalculated/TotalCount
  74. }
  75. /////////////////////////////////////////////////
  76.  
  77. }
  78.  
  79. delay(50);
  80. }
  81.  
  82.  
  83.  
  84. uint8_t getFingerprintID() {
  85. uint8_t p = finger.getImage();
  86. switch (p) {
  87. case FINGERPRINT_OK:
  88. Serial.println("Image taken");
  89. break;
  90. case FINGERPRINT_NOFINGER:
  91. Serial.println("No finger detected");
  92. return p;
  93. case FINGERPRINT_PACKETRECIEVEERR:
  94. Serial.println("Communication error");
  95. return p;
  96. case FINGERPRINT_IMAGEFAIL:
  97. Serial.println("Imaging error");
  98. return p;
  99. default:
  100. Serial.println("Unknown error");
  101. return p;
  102. }
  103.  
  104. // OK success!
  105.  
  106. p = finger.image2Tz();
  107. switch (p) {
  108. case FINGERPRINT_OK:
  109. Serial.println("Image converted");
  110. break;
  111. case FINGERPRINT_IMAGEMESS:
  112. Serial.println("Image too messy");
  113. return p;
  114. case FINGERPRINT_PACKETRECIEVEERR:
  115. Serial.println("Communication error");
  116. return p;
  117. case FINGERPRINT_FEATUREFAIL:
  118. Serial.println("Could not find fingerprint features");
  119. return p;
  120. case FINGERPRINT_INVALIDIMAGE:
  121. Serial.println("Could not find fingerprint features");
  122. return p;
  123. default:
  124. Serial.println("Unknown error");
  125. return p;
  126. }
  127.  
  128. // OK converted!
  129. p = finger.fingerSearch();
  130. if (p == FINGERPRINT_OK) {
  131. Serial.println("Found a print match!");
  132. } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
  133. Serial.println("Communication error");
  134. return p;
  135. } else if (p == FINGERPRINT_NOTFOUND) {
  136. Serial.println("Did not find a match");
  137. return p;
  138. } else {
  139. Serial.println("Unknown error");
  140. return p;
  141. }
  142.  
  143. // found a match!
  144. Serial.print("Found ID #"); Serial.print(finger.fingerID);
  145. Serial.print(" with confidence of "); Serial.println(finger.confidence);
  146.  
  147. return finger.fingerID;
  148. }
  149.  
  150. // returns -1 if failed, otherwise returns ID #
  151. int getFingerprintIDez() {
  152. uint8_t p = finger.getImage();
  153. if (p != FINGERPRINT_OK) return -1;
  154.  
  155. p = finger.image2Tz();
  156. if (p != FINGERPRINT_OK) return -1;
  157.  
  158. p = finger.fingerFastSearch();
  159. if (p != FINGERPRINT_OK) return -1;
  160.  
  161. // found a match!
  162. Serial.print("Found ID #"); Serial.print(finger.fingerID);
  163. Serial.print(" with confidence of "); Serial.println(finger.confidence);
  164. return finger.fingerID;
  165. }
  166.  
  167. void initFingerPrint() {
  168. Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2);
  169. while (!Serial);
  170. delay(100);
  171. Serial.println("\n\nAdafruit finger detect test");
  172. delay(5);
  173. if (finger.verifyPassword()) {
  174. Serial.println("Found fingerprint sensor!");
  175. } else {
  176. Serial.println("Did not find fingerprint sensor :(");
  177. while (1) {
  178. delay(1);
  179. }
  180. }
  181.  
  182. Serial.println(F("Reading sensor parameters"));
  183. finger.getParameters();
  184. Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  185. Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  186. Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  187. Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  188. Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  189. Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  190. Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
  191.  
  192. finger.getTemplateCount();
  193.  
  194. if (finger.templateCount == 0) {
  195. Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
  196. }
  197. else {
  198. Serial.println("Waiting for valid finger...");
  199. Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  200. }
  201. }
  202.  
  203. void resetData() {
  204. StudentNumber[numberOfStudents] = 0;
  205. ParentNumber[numberOfStudents] = 0;
  206. totalCount = numberOfStudents;
  207. totalCountCalculated = 0;
  208. }
  209.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement