q
#include <ID1016C.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RST_PIN 4
Adafruit_SSD1306 display(OLED_RST_PIN);
ID1016C C1016;
uint32_t finger_num = 0;? //讀取的指紋編號(hào)
uint32_t input_finger_num = 1;? //指定要錄入的指紋編號(hào)
int key1 = 49;? //設(shè)置按鍵IO
int key2 = 48;? //設(shè)置按鍵IO
void setup() {
? C1016.ID1016C_Init();
? delay(500);
? display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
? Serial.begin(115200);
? pinMode(key1, INPUT);
? pinMode(key2, INPUT);
? display.clearDisplay();? // 清屏
? display.setTextSize(1);? //設(shè)置字體大小
? display.setTextColor(WHITE);
? display.setCursor(0, 0);
? display.setCursor(30, 0);
? display.println("指紋測試");
? display.display();
}
void loop() {
? C1016.ID1016C_Weakup();
? switch (key_scan()) {
? ? case 1:
? ? ? C1016.C1016_Enroll(input_finger_num);? // 錄入指紋
? ? ? display.clearDisplay();? ?
? ? ? display.setCursor(0, 10);
? ? ? display.println("錄入成功");
? ? ? display.print("指紋編號(hào):");
? ? ? display.print(input_finger_num);
? ? ? display.display();
? ? ? break;
? ? case 2:
? ? ? finger_num = C1016.C1016_Identify();? // 識(shí)別指紋
? ? ? display.clearDisplay();? ? ? ? ? ? ? ? ??
? ? ? if (finger_num == 0) {
? ? ? ? display.setCursor(0, 20);
? ? ? ? display.print("未識(shí)別到指紋");
? ? ? } else {
? ? ? ? display.setCursor(0, 20);
? ? ? ? display.print("指紋編號(hào):");
? ? ? ? display.print(finger_num);
? ? ? }
? ? ? display.display();
? ? ? break;
? ? case 3:? //指紋編號(hào)+1,方便錄入下一個(gè)指紋
? ? ? display.setCursor(0, 10);
? ? ? display.clearDisplay();? ? ? ? ? ? ? ??
? ? ? input_finger_num++;
? ? ? display.print("將錄入指紋編號(hào):");? //顯示將要錄入指紋的編號(hào)
? ? ? display.print(input_finger_num);
? ? ? display.display();
? ? ? break;
? ? case 4:? // 清除所有指紋信息
? ? ? C1016.C1016_cmd_Delete();? // 清除所有指紋信息
? ? ? display.clearDisplay();? ??
? ? ? display.setCursor(0, 40);
? ? ? display.print("清除所有指紋信息");
? ? ? display.display();
? ? ? break;
? ? default:
? ? ? break;
? }
? display.setCursor(30, 0);
? display.println("指紋測試");
? display.display();
}
uint8_t key_scan() {
? uint8_t i = 0;
? if (digitalRead(key1) == 0) {
? ? delay(20);
? ? if (digitalRead(key1) == 0) {
? ? ? while (digitalRead(key1) == 0) {
? ? ? ? delay(1);
? ? ? ? i++;
? ? ? ? if (i > 200) {
? ? ? ? ? while (digitalRead(key1) == 0);
? ? ? ? ? return 3;
? ? ? ? }
? ? ? }
? ? ? return 1;
} else if (digitalRead(key2) == 0) {
? delay(20);
? if (digitalRead(key2) == 0) {
? ? while (digitalRead(key2) == 0) {
? ? ? delay(1);
? ? ? i++;
? ? ? if (i > 200) {
? ? ? ? while (digitalRead(key2) == 0);
? ? ? ? return 4;
? ? ? }
? ? }
? ? return 2;
? }
}
return 0;?
}