Running a second program after the first one is complete.

I am trying to run the clock program after the "DIY Fingerprint Bio metric Arduino Anti-thief Security System" program as completed.(http://www.instructables.com/id/Biometric-Arduino-Engine-Security-System/)
The clock program starts but the LCD does not update the clock.

#include <LiquidCrystal.h>
#include <Adafruit_Fingerprint.h>
#include "Time.h"
#include "DS1307RTC.h"
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
#define label1
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int getFingerprintIDez();
SoftwareSerial mySerial(2, 3);// tx, rx
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}

void setup()
{
pinMode(8, OUTPUT);
digitalWrite(8,LOW);
lcd.begin(16, 2);
finger.begin(57600);
if (finger.verifyPassword())
{
}
else {
lcd.print("Sensor error");
while (1);
}
lcd.clear();
lcd.print("No valid finger");
lcd.setCursor(0, 1);
lcd.print("on the sensor..,");
digitalWrite(8, LOW);

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
}

void loop()
{
if(getFingerprintIDez()>=0)
{
}
}
uint8_t getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
lcd.print("Image taken");
break;
case FINGERPRINT_NOFINGER:
lcd.print("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
lcd.print("Comms error");
return p;
case FINGERPRINT_IMAGEFAIL:
lcd.print("Imaging error");
return p;
default:
lcd.print("Unknown error");
return p;
}

p = finger.image2Tz();
switch (p)
{
case FINGERPRINT_OK:
lcd.print("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
lcd.print("Image messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
lcd.print("Comms error");
return p;
case FINGERPRINT_FEATUREFAIL:
lcd.print("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
lcd.print("Could not find fingerprint features");
return p;
default:
lcd.print("Unknown error");
return p;
}

p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK)
{
}

}

// 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;
{
digitalWrite(8, HIGH);// Vehicle starter relay On
lcd.clear();
lcd.print("Unlocked");
// fingerprint program ends here

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String s, m, d, mth, h;

getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

if (second < 10) { s = "0" + String(second); } else { s = String(second); }
if (minute < 10) { m = "0" + String(minute); } else { m = String(minute); }
h = String(hour);
if (dayOfMonth < 10) { d = "0" + String(dayOfMonth); } else { d = String(dayOfMonth); }
if (month < 10) { mth = "0" + String(month); } else { mth = String(month); }

char* days[] = { "NA", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };

lcd.clear();
lcd.setCursor(4,0);
lcd.print(h + ":" + m + ":" + s);
lcd.setCursor(1,1);
lcd.print(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year);
delay(1000); // Wait 1 second
}
}

fingerprint_carunlock_clock.ino (3.7 KB)

Since that program never completes, you don't have to worry about running another program AFTER it.

You might want to do something when some portion of the program has done something.

Quit pissing away resources using Strings. A string and sprintf() will do everything you need to.

I am a 55 yr old newbie in Arduino programming ( I can modify a downloaded or write simple sketch) , I am good in electronics and not in programming.
I have made a Co2 sensor which controls the vents of My SUV, and I wanted to add a fingerprint ignition unlock-er which would run the Co2 or Clock on the same LCD after the system is unlocked by the fingerprint sensor.

Have a look at Planning and Implementing a Program

If you look at the code in loop() you will see a series of function calls

void loop() {
   flashLedA();
   flashLedB();
   checkButtons();
   setFlashPeriod();
   askForUserInput();
   getUserResponse();
   moveServo();
   readPotentiometer();
   setServoPosition();
}

You could think of those as a series of programs that run one after the other.

...R

Thanks Robin2

I got project running .

#include "Wire.h"
#include <LiquidCrystal.h>
#define DS1307_I2C_ADDRESS 0x68
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#include <Adafruit_Fingerprint.h>
int getFingerprintIDez();
SoftwareSerial mySerial(2, 3);// tx, rx
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int count = 0;
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}

void setup()
{
pinMode(10, OUTPUT); // Connect to starter relay.
pinMode(11, OUTPUT); // connect to fingerprint sensor.
digitalWrite(11,HIGH); // switch On fingerprint sensor.
lcd.begin(16, 2);
finger.begin(57600);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
}
void sensor()
{
if(getFingerprintIDez()>=0) // Only registered fingerprints.
{
digitalWrite(10,HIGH); // Activate starter Relay.
digitalWrite(11,LOW); // switch Off fingerprint sensor.
lcd.setCursor(6,0);
lcd.print("Unlocked-");lcd.write(0b11111100);
}
delay(500); // fingerprintsensor LED flash rate.
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez()
{
if (!finger.verifyPassword())
{
return -1;
}

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;
}
return finger.fingerID;
}

void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String s, m, d, mth, h;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (second < 10) { s = "0" + String(second); } else { s = String(second); }
if (minute < 10) { m = "0" + String(minute); } else { m = String(minute); }
h = String(hour);
if (dayOfMonth < 10) { d = "0" + String(dayOfMonth); } else { d = String(dayOfMonth); }
if (month < 10) { mth = "0" + String(month); } else { mth = String(month); }
char* days[] = { "NA", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
lcd.setCursor(0,0);
lcd.print(h + ":" + m);
lcd.setCursor(0,1);
// PREFIX THE 20 AS THE RTC CHIP ONLY USES 2 DIGITS FOR THE YEAR //
lcd.print(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year);
delay(1000); // Wait 1 second
sensor();
}

  lcd.print(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year);

You REALLY could do this with 7 calls to lcd.print() without pissing away any resources on the String class.

Or use one call to lcd.print() to print a string populated by sprintf() and still have smaller code.

You don't run a second program that runs after the first is complete. You have one program that does thing A or does thing B when it's appropriate for it to do so.