Pages: [1]   Go Down
Author Topic: Joining two programs together  (Read 597 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all. I am trying to join these to programs together but cant get it working correctly. I keep getting loads of errors.

First program.
Code:

#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

int getFingerprintIDez();


#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

#define redLedPin 12
#define greenLedPin 11

void setup()  
{
  Serial.begin(9600);
  Serial.println("fingertest");
  

  
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, HIGH);
}

void loop()                    
{
  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;
  }
  
 
  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);
}


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;
  
  
  digitalWrite(redLedPin, HIGH);
  digitalWrite(greenLedPin, LOW);
  lcd.print("Hi Enter");
  delay(3000);
  lcd.clear();
  digitalWrite(greenLedPin, HIGH);
  delay(1000);
  digitalWrite(redLedPin, LOW);
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID;
}

Second program.
Code:
 
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
Password password = Password( "147*" );
const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0',' '}
};

byte rowPins[ROWS] = {7,6,5,4};
byte colPins[COLS] = {10,9,8};
const int buttonPin = 52;
int buttonState = 0;


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define redLedPin 12
#define greenLedPin 11

void setup(){
   pinMode(redLedPin, OUTPUT);
   pinMode(greenLedPin, OUTPUT);
   digitalWrite(redLedPin, LOW);
   digitalWrite(greenLedPin, HIGH);
lcd.begin(16, 2);
digitalWrite(redLedPin, LOW);
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
keypad.setDebounceTime(250);
}

void loop(){
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}
}


void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(redLedPin,HIGH);
digitalWrite(greenLedPin,LOW);
delay(2000);
lcd.print("Hi ");
password.reset();
delay(1000);
lcd.print("Enter");
delay(2000);


digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(12, LOW);

lcd.clear();
}


else{
digitalWrite(redLedPin,LOW);
lcd.print("GET OUT ");
password.reset();
delay(3000);
lcd.clear();
}
}

Any help would be with this problem would be much appreciated. Thank you.
« Last Edit: February 12, 2013, 06:36:00 am by heffo78 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 611
Posts: 49098
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any help will come after you do several things. First, and most important is to fix your post, and post the code properly. Select each program and use the icon with the # symbol to add code tags, to prevent the mangling that has happened with your code.

Second, you must define the requirements for your combined program.

Third, you must post your attempt to combine them.

Finally, I'm pretty sure the compiler was a bit more specific than "loads of errors.". What errors?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Start by combining the code that goes before void setup,
then combine the code in void setup,
then combine the code in void loop,
then paste in the remaining functions.

Will look something like this - I already deleted the duplicate pin assignments and pinMode/digital writes.
Now its your turn to see if the combo does what you want
(I didn't compile it, so it may have some errors to fix still)
Code:
#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>

int getFingerprintIDez();


#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

#define redLedPin 12
#define greenLedPin 11
Password password = Password( "147*" );
const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0',' '}
};

byte rowPins[ROWS] = {7,6,5,4};
byte colPins[COLS] = {10,9,8};
const int buttonPin = 52;
int buttonState = 0;


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup()
{
Serial.begin(9600);
Serial.println("fingertest");



finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor ");
while (1);
}
Serial.println("Waiting for valid finger...");
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, HIGH);

lcd.begin(16, 2);
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
keypad.setDebounceTime(250);
}

void loop()
{
getFingerprintIDez();
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}

}

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;
}


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);
}


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;


digitalWrite(redLedPin, HIGH);
digitalWrite(greenLedPin, LOW);
lcd.print("Hi Enter");
delay(3000);
lcd.clear();
digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(redLedPin, LOW);
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(redLedPin,HIGH);
digitalWrite(greenLedPin,LOW);
delay(2000);
lcd.print("Hi ");
password.reset();
delay(1000);
lcd.print("Enter");
delay(2000);


digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(12, LOW);

lcd.clear();
}


else{
digitalWrite(redLedPin,LOW);
lcd.print("GET OUT ");
password.reset();
delay(3000);
lcd.clear();
}
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Crossroads. I will test it tomorrow and let you know how it goes. I really appreciate your help. Thank you.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have all these libraries, so I can't compile it to check errors. The code needs some arranging still, see the notes below, these things will get ya:

#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal.h>
>> LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);  this line needs to get moved after the # include lines, and delete the duplicate LiquidCrystal.h
#include <SoftwareSerial.h>  >> probably just one or the other of these
#include <NewSoftSerial.h>  >> probably just one or the other of these
#include <Password.h>
#include <LiquidCrystal.h>  >> duplicate, delete

Good luck.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Crossroads. This program is now working. Thanks very much for your help.
This is the code with the few changes.
Thanks again

Code:
#include <Adafruit_Fingerprint.h>
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);

int getFingerprintIDez();


#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);


Password password = Password( "147*" );
const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0',' '}
};

byte rowPins[ROWS] = {7,6,5,4};
byte colPins[COLS] = {10,9,8};
const int buttonPin = 52;
int buttonState = 0;


Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define redLedPin 12
#define greenLedPin 11

void setup()
{
Serial.begin(9600);
Serial.println("fingertest");



finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor ");
while (1);
}
Serial.println("Waiting for valid finger...");
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, HIGH);

lcd.begin(16, 2);
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
keypad.setDebounceTime(250);
}

void loop()
{
getFingerprintIDez();
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}

}

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;
}


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);
}


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;


digitalWrite(redLedPin, HIGH);
digitalWrite(greenLedPin, LOW);
lcd.print("Hi Enter");
delay(3000);
lcd.clear();
digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(redLedPin, LOW);
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(redLedPin,HIGH);
digitalWrite(greenLedPin,LOW);
delay(2000);
lcd.print("Hi ");
password.reset();
delay(1000);
lcd.print("Enter");
delay(2000);


digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(12, LOW);

lcd.clear();
}


else{
digitalWrite(redLedPin,LOW);
lcd.print("GET OUT ");
password.reset();
delay(3000);
lcd.clear();
}
}
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Cool.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how if i want to dispaly it on LCD using liquidcrystal.h library.. can i get the coding coz im doing same project like this and how to make the password have 3x trials..
Logged

Pages: [1]   Go Up
Jump to: