1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
int PWMA = 11;
int DIRA = 13;
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include<MsTimer2.h>
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED 1
SoftwareSerial mySerial(2, 3);
SoftwareSerial BLE(RxD, TxD);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setupBleConnection()
{
BLE.begin(9600); //Set BLE BaudRate to default baud rate 9600
delay(1000);
BLE.print("AT+CLEAR"); //clear all previous setting
delay(3000);
BLE.print("AT+ROLE0"); //set the bluetooth name as a slaver
delay(2000);
BLE.print("AT+SAVE1"); //don't save the connect information
delay(2000);
}
void setup() {
pinMode (DIRA, OUTPUT);
Serial.begin(9600);
delay(100);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBleConnection();
Serial.println("\n\nAdafruit finger detect test");
finger.begin(57600);
delay(5);
finger.getTemplateCount();
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
Serial.println("Waiting for valid finger...");
}
void bluetooth()
{
char recvChar;
while (1) {
if (BLE.available()) { //check if there's any data sent from the remote BLE
recvChar = BLE.read();
Serial.print(recvChar);
}
if (Serial.available()) { //check if there's any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
BLE.print(recvChar);
}
}
}
char recvChar;
void loop() {
delay(50);
if (BLE.available()) { //check if there's any data sent from the remote BLE
recvChar = BLE.read();
Serial.print(recvChar);
}
if (Serial.available()) { //check if there's any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
BLE.print(recvChar);
}
getFingerprintIDez();
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
digitalWrite(DIRA, 1);
analogWrite(PWMA, 255);
delay(200);
int(a) = 0;
while (a < 25) {
analogWrite(0, 0);
delay(0.02);
a = analogRead(1);
char recvChar;
recvChar = BLE.read();
Serial.println(recvChar);
if (BLE.available()) { //check if there's any data sent from the remote BLE
recvChar = BLE.read();
if (recvChar="stop"){
break;}
}
}
digitalWrite(PWMA, 0);
delay(6000);
digitalWrite(DIRA, 0);
analogWrite(PWMA, 255);
delay(400);
a = 0;
while (a < 25) {
a = analogRead(1);
Serial.println(a);
}
digitalWrite(PWMA, 0);
return finger.fingerID;
} |
Partager