[mw_shl_code=arduino,true]/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百五十:AS608光学指纹识别模块+0.91寸OLED液晶屏显示模块
安装AS608库:IDE—工具—管理库—搜索Adafruit-Fingerprint-Sensor-Library—安装
安装OLED库:IDE—工具—管理库—搜索Adafruit_SSD1306—安装
安装OLED库:IDE—工具—管理库—搜索Adafruit_GFX—安装
实验程序之十三:识别指纹ID,OLED显示识别人名
AS608模块实验接线
Vi +3.3V(请勿接3.3V以上电源,否则烧毁模块!)
TX 2
RX 3
GND GND
OLED 屏幕实验接线
oled模块 Ardunio Uno
GND---------GND接地线
VCC---------5V 接电源
SDA---------A4
SCL ------- A5
*/
#include
#include
#include
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#include
#include
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0;
String IDname;
void setup() {
//Fingerprint sensor module setup
Serial.begin(9600);
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
}
else {
Serial.println("Did not find fingerprint sensor
");
while (1) {
delay(1);
}
}
//OLED display setup
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//displays main screen
displayMainScreen();
}
void loop() {
displayMainScreen();
fingerprintID = getFingerprintIDez();
delay(50);
if (fingerprintID == 1 || fingerprintID == 3) {
IDname = "huadiao";
displayUserGreeting(IDname);
}
else if (fingerprintID == 2) {
IDname = "zhanghaoze";
displayUserGreeting(IDname);
}
}
// returns -1 if failed, otherwise returns ID #
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;
// found a match!
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
return finger.fingerID;
}
void displayMainScreen() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(7, 5);
display.println("Waiting fingerprint");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(52, 20);
display.println("...");
display.display();
delay(2000);
}
void displayUserGreeting(String Name) {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0, 0);
display.print("Hello");
display.setCursor(0, 15);
display.print(Name);
display.display();
delay(5000);
fingerprintID = 0;
}[/mw_shl_code]