/*
Casey Fulford Biometrics TLI 31300
Project 3 - Bar Graph with Potentiometer
For this I used a fingerprint scanner to turn on the light program
Need to register fingerprints with the Adafruit Enroll program
*/
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0; // Set this to 0 for a place holder
int getFingerprintIDez(); // Function declaraton. This calls the get.finger object from the Adafruit library
const int potPin = A0; // Analog input pin connected to the potentiometer
int potValue = 0; // Value that will be read from the potentiometer
const int ledCount = 9;
int ledPins[] = {2,3,4,5,6,7,8,9,10};
boolean mainUser; // This is a true / false for showing the main user
void setup()
{
for (int thisLed = 0; thisLed < ledCount; thisLed++)
{
pinMode(ledPins[thisLed], OUTPUT); // Set the LED pins as output
}
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\nAdafruit finger detect test");
// 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); }
}
finger.getTemplateCount();
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
Serial.println("Waiting for valid finger...");
}
void loop()
{
fingerprintID = getFingerprintIDez();
delay(50);
if (fingerprintID == 1)
{
mainUser = true;
}
else if (fingerprintID != 1)
{
mainUser = false;
}
while (mainUser)
{
int sensorReading = analogRead(analogPin); // Analog input
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++)
{
if (thisLed < ledLevel)
{
digitalWrite(ledPins[thisLed], HIGH);
}
else
{ // Turn off LEDs in sequence
digitalWrite(ledPins[thisLed], LOW);
}
}
}
if (mainUser = false)
{
digitalWrite(buzzerPin, HIGH); // Send potentiometer value to LED
digitalWrite(errorPin, HIGH); // Send potentiometer value to LED
delay(500);
}
} // end of main
// 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;
}
Comments
Please log in or sign up to comment.