door lock problems, help all

I have the final module with servo door lock password, and run into problems, which I want to put the RTC as the primary display, and if the keypad on tap function switch to the keypad, this is his sketch I attach, please help all

#include <Password.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
#include “RTClib.h”
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {“MINGGU”, “SENIN”, “SELASA”, “RABU”, “KAMIS”, “JUMAT”, “SABTU”};

int position = 0;
byte currentLength = 0;
Servo myservo;
int passwd_pos = 9;

int buzzer = 13;
int redLED = 12;
int greenLED = 11;
int blueLED = 10;
int relay = 1;
int led = A0;

Password password = Password( “100488” );
String tempPassword="";
int currentPosition = 0;
int layarUtama = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
‘1’,‘2’,‘3’,‘A’, }
,
{
‘4’,‘5’,‘6’,‘B’, }
,
{
‘7’,‘8’,‘9’,‘C’, }
,
{
‘*’,‘0’,’#’,‘D’, }
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int detect_Keypad;
void setup(){
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("==DOOR LOCK BY==");
lcd.setCursor(0,1);
lcd.print("====AATTSANI====");
delay(2000);
while (!Serial);

Serial.begin(9600);
if (! RTC.begin()){
Serial.println(“RTC tidak ditemukan”);
while (1);
}
if (! RTC.isrunning()){
Serial.println(“RTC Tidak Bekerja”);
}
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(DATE,TIME));
keypad.setDebounceTime(50);
keypad.addEventListener(keypadEvent);
myservo.attach(A1);
myservo.write(0);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(led, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
digitalWrite(blueLED, LOW);
digitalWrite(relay, LOW);
displayCodeEntryScreen();

}

void loop(){
keypad.getKey();
}

void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
if (passwd_pos - 9 >= 20){
return;
}
lcd.setCursor((passwd_pos++), 1);
switch (eKey){
case ‘#’ : passwd_pos = 9;
checkPassword(); break;
case '’ : passwd_pos = 9;
password.reset(); break;
default:
password.append(eKey);
lcd.print("
");
beep();
}
}
}

void displayCodeEntryScreen(){
lcd.clear();
password.reset();
lcd.clear();
delay(20);
int i;
lcd.setCursor (0,0);
lcd.print ("====SILAHKAN====");
lcd.setCursor (0,1);
lcd.print (“Ent PIN:”);
}

void checkPassword(){
if (password.evaluate()){
int i;
for (i=1; i <= 2; i++)
{
beep1();
}
lcd.clear();
delay(30);
lcd.setCursor(2,0);
lcd.print(“PIN DITERIMA”);
lcd.setCursor(1,2);
lcd.print(“KUNCI TERBUKA”);
kunciDibuka();
digitalWrite(blueLED, LOW);
kunciDitutup();
setup();
}
else {
loop();{
lcd.clear();
delay(10);
lcd.setCursor(2,0);
lcd.print(“PIN DITOLAK”);
lcd.setCursor(2,1);
lcd.print(“COBA KEMBALI”);
attention();
lcd.clear();
setup();
}
}
}

void beep(){
digitalWrite (buzzer, HIGH);
digitalWrite (greenLED, HIGH);
delay(70);
digitalWrite (buzzer, LOW);
digitalWrite (greenLED, LOW);
delay(70);
}

void beep1(){
digitalWrite (buzzer, HIGH);
digitalWrite (greenLED, HIGH);
delay(150);
digitalWrite (buzzer, LOW);
digitalWrite (greenLED, LOW);
delay(150);
digitalWrite (buzzer, HIGH);
digitalWrite (greenLED, HIGH);
delay(150);
digitalWrite (buzzer, LOW);
digitalWrite (greenLED, LOW);
delay(150);
}

void beep2(){
digitalWrite (buzzer, HIGH);
digitalWrite (redLED, HIGH);
delay(250);
digitalWrite (buzzer, LOW);
digitalWrite (redLED, LOW);
delay(250);
digitalWrite (buzzer, HIGH);
digitalWrite (redLED, HIGH);
delay(250);
digitalWrite (buzzer, LOW);
digitalWrite (redLED, LOW);
delay(250);
digitalWrite (buzzer, HIGH);
digitalWrite (redLED, HIGH);
delay(250);
digitalWrite (buzzer, LOW);
digitalWrite (redLED, LOW);
delay(250);
}

void kunciDibuka(){
myservo.write(110);
digitalWrite(relay, HIGH);
analogWrite(blueLED, 255);
delay(10000);
jamDigital();
delay(1000);
analogWrite(blueLED, 0);

}
void beep3(){
digitalWrite (led, HIGH);
delay(50);
digitalWrite (led, LOW);
delay(2000);
}

void kunciDitutup(){
beep2();
lcd.clear();
digitalWrite(relay, LOW);
digitalWrite(blueLED, LOW);
myservo.write(0);
lcd.setCursor(1,0);
lcd.print(“PINTU TERKUNCI”);
lcd.setCursor(4,1);
lcd.print(“OTOMATIS”);
delay(1000);
lcd.setCursor(1,0);
lcd.print(“UNTUK MEMBUKA”);
lcd.setCursor(1,1);
lcd.print(“PINTU KEMBALI”);
delay(1000);
}

void attention(){
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
}

void jamDigital(){
lcd.clear();
DateTime now = RTC.now();
lcd.setCursor(0,0);
lcd.print(now.day(), DEC);
lcd.print(’/’);
lcd.print(now.month(), DEC);
lcd.print(’/’);
lcd.print(now.year(), DEC);
lcd.print(’ ‘);
lcd.setCursor(10,0);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.setCursor(4,1);
lcd.print(now.hour(), DEC);
lcd.print(’:’);
lcd.setCursor(7,1);
lcd.print(now.minute(), DEC);
lcd.print(’:’);
lcd.setCursor(10,1);
lcd.print(now.second(), DEC);
Serial.println();
}

In principle, you set/refresh a timer every time keyboard activity is detected.

unsigned long lastKeyDetectedAtMs = millis();

In the loop, you periodically check this, and if the last detection is more than say 5 seconds old, you display the time/date.

if ( millis() - lastKeyDetectedAtMs > 5000 ) {
  // display date
}

Use code tags if you post code here.

6v6gt: In principle, you set/refresh a timer every time keyboard activity is detected.

unsigned long lastKeyDetectedAtMs = millis();

In the loop, you periodically check this, and if the last detection is more than say 5 seconds old, you display the time/date.

if ( millis() - lastKeyDetectedAtMs > 5000 ) {
  // display date
}

Use code tags if you post code here.

6v6gt: In principle, you set/refresh a timer every time keyboard activity is detected.

unsigned long lastKeyDetectedAtMs = millis();

In the loop, you periodically check this, and if the last detection is more than say 5 seconds old, you display the time/date.

if ( millis() - lastKeyDetectedAtMs > 5000 ) {
  // display date
}

Use code tags if you post code here.

6v6gt: In principle, you set/refresh a timer every time keyboard activity is detected.

unsigned long lastKeyDetectedAtMs = millis();

In the loop, you periodically check this, and if the last detection is more than say 5 seconds old, you display the time/date.

if ( millis() - lastKeyDetectedAtMs > 5000 ) {
  // display date
}

Use code tags if you post code here.

I was new master sorry about arduino so still confused, still can not display the hour, this is his sketch

void loop(){

char detect_keypad = keypad.getKey();
unsigned long lastKeyDetectedAtMs = millis();

if ( millis() - lastKeyDetectedAtMs > 5000 ) {
  jamDigital();// display date
}

  
}
  1. Can you go back and edit the first post so all that code is between code tags because it is very long to scroll through ?

  2. add a global variable to your other global variables :

unsigned long lastKeyDetectedAtMs ;
  1. change your loop() to this:
void loop(){
  keypad.getKey();
  if ( millis() - lastKeyDetectedAtMs > 5000 ) {
     jamDigital();// display date
  }
}
  1. add an extra statement to function keypadEvent to update lastKeyDetectedAtMs when a key press is detected:
void keypadEvent(KeypadEvent eKey){
   lastKeyDetectedAtMs = millis() ; 
   . . .
   . . .
}

6v6gt:

  1. Can you go back and edit the first post so all that code is between code tags because it is very long to scroll through ?

  2. add a global variable to your other global variables :

unsigned long lastKeyDetectedAtMs ;
  1. change your loop() to this:
void loop(){

keypad.getKey();
  if ( millis() - lastKeyDetectedAtMs > 5000 ) {
    jamDigital();// display date
  }
}




4. add an extra statement to function keypadEvent to update lastKeyDetectedAtMs when a key press is detected:



void keypadEvent(KeypadEvent eKey){
  lastKeyDetectedAtMs = millis() ;
  . . .
  . . .
}

Ok im try this sketch

#include <Password.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
#include "RTClib.h"
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {"MINGGU", "SENIN", "SELASA", "RABU", "KAMIS", "JUMAT", "SABTU"};

int position = 0;
byte currentLength = 0;
Servo myservo;
int passwd_pos = 9;

int buzzer = 13;
int redLED = 12;
int greenLED = 11;
int blueLED = 10;
int relay = 1;
int led = A0;

Password password = Password( "100488" );
String tempPassword="";
int currentPosition = 0;
int layarUtama = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
  '1','2','3','A',  }
,
{
  '4','5','6','B',  }
,
{
  '7','8','9','C',  }
,
{
  '*','0','#','D',  }
};

byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2}; 

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int detect_Keypad;
void setup(){
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("==DOOR LOCK BY==");
lcd.setCursor(0,1);
lcd.print("====AATTSANI====");
delay(2000);
while (!Serial);

Serial.begin(9600);
if (! RTC.begin()){
  Serial.println("RTC tidak ditemukan");
  while (1);
}
if (! RTC.isrunning()){
  Serial.println("RTC Tidak Bekerja");
}
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__,__TIME__));
keypad.setDebounceTime(50);
keypad.addEventListener(keypadEvent);
myservo.attach(A1);
myservo.write(0);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(led, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
digitalWrite(blueLED, LOW);
digitalWrite(relay, LOW);
displayCodeEntryScreen();

}

void loop(){
keypad.getKey();
}

void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
  case PRESSED:
  if (passwd_pos - 9 >= 20){
    return;
  }
  lcd.setCursor((passwd_pos++), 1);
  switch (eKey){
    case '#' : passwd_pos = 9;
    checkPassword(); break;
    case '*' : passwd_pos = 9;
    password.reset(); break;
    default:
    password.append(eKey);
    lcd.print("*");
    beep();
  }
}
}

void displayCodeEntryScreen(){
lcd.clear();
password.reset();
lcd.clear();
delay(20);
int i;
lcd.setCursor (0,0);
lcd.print ("====SILAHKAN====");
lcd.setCursor (0,1);
lcd.print ("Ent PIN:");
}

void checkPassword(){
if (password.evaluate()){
  int i;
  for (i=1; i <= 2; i++)
  {
    beep1();
  }
  lcd.clear();
  delay(30);
  lcd.setCursor(2,0);
  lcd.print("PIN DITERIMA");
  lcd.setCursor(1,2);
  lcd.print("KUNCI  TERBUKA");
  kunciDibuka();
  digitalWrite(blueLED, LOW);   
  kunciDitutup();
  setup();
}
else {
  loop();{
    lcd.clear();
    delay(10);
    lcd.setCursor(2,0);
    lcd.print("PIN  DITOLAK");
    lcd.setCursor(2,1);
    lcd.print("COBA KEMBALI");
    attention();
    lcd.clear();
    setup();
  }
}
}


void beep(){
digitalWrite (buzzer, HIGH);
digitalWrite (greenLED, HIGH);
delay(70);
digitalWrite (buzzer, LOW);
digitalWrite (greenLED, LOW);
delay(70);
}

void beep1(){
digitalWrite (buzzer, HIGH);
digitalWrite (greenLED, HIGH);
delay(150);
digitalWrite (buzzer, LOW);
digitalWrite (greenLED, LOW);
delay(150);
digitalWrite (buzzer, HIGH);
digitalWrite (greenLED, HIGH);
delay(150);
digitalWrite (buzzer, LOW);
digitalWrite (greenLED, LOW);
delay(150);
}

void beep2(){
digitalWrite (buzzer, HIGH);
digitalWrite (redLED, HIGH);
delay(250);
digitalWrite (buzzer, LOW);
digitalWrite (redLED, LOW);
delay(250);
digitalWrite (buzzer, HIGH);
digitalWrite (redLED, HIGH);
delay(250);
digitalWrite (buzzer, LOW);
digitalWrite (redLED, LOW);
delay(250);
digitalWrite (buzzer, HIGH);
digitalWrite (redLED, HIGH);
delay(250);
digitalWrite (buzzer, LOW);
digitalWrite (redLED, LOW);
delay(250);
}

void kunciDibuka(){
myservo.write(110);
digitalWrite(relay, HIGH);
analogWrite(blueLED, 255);
delay(10000);
jamDigital();
delay(1000);
analogWrite(blueLED, 0);

}
void beep3(){
digitalWrite (led, HIGH);
delay(50);
digitalWrite (led, LOW);
delay(2000);
}

void kunciDitutup(){
beep2();
lcd.clear();
digitalWrite(relay, LOW);
digitalWrite(blueLED, LOW);
myservo.write(0);
lcd.setCursor(1,0);
lcd.print("PINTU TERKUNCI");
lcd.setCursor(4,1);
lcd.print("OTOMATIS");
delay(1000);
lcd.setCursor(1,0);
lcd.print("UNTUK  MEMBUKA");
lcd.setCursor(1,1);
lcd.print("PINTU  KEMBALI");
delay(1000);
}

void attention(){
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
delay(100);
}

void jamDigital(){
lcd.clear();
DateTime now = RTC.now();
lcd.setCursor(0,0);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.print(' ');
lcd.setCursor(10,0);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.setCursor(4,1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.setCursor(7,1);
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.setCursor(10,1);
lcd.print(now.second(), DEC);
Serial.println();
}