programming problems

Yup, that would be it!

I was editing that post and trying things out while also trying to look it up in tabs and then I couldn't edit my post and lost the page, such a mess this morning (it is 7:03AM here) but no biggie after all!

I did notice that the code boxes now have Select in blue up there so I clicked and the code selects. That's a nice little thing but my memory isn't so good... did we have that before?

#include <Keypad.h>
#include <Password.h>
char* secretCode = "123";
int position = 0;
const byte ROWS = 4; 
const byte COLS = 3; 
const int button = 13;
const int alarm = 12;
const int led_alarm = 11;
const int del_time = A0;
const int led_pass = 10;
int b=HIGH;
int val_a;
int val_d;
char keys[ROWS][COLS] =
{
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; 
byte colPins[COLS] = {4, 3, 2}; 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
   pinMode(alarm, INPUT);
   pinMode(led_alarm, OUTPUT);
   pinMode(led_pass, OUTPUT);
  setLocked(true);
  
}
void loop() 
{
  val_a= digitalRead(alarm);
  val_d= analogRead(del_time);
  if (val_a == LOW)
  {
  //  delay (5000);
    if (b == HIGH){
    digitalWrite (led_alarm, HIGH);
   // delay (5000);
    }
    else if (b == LOW){
      digitalWrite (led_alarm, LOW);
    }
  }
  else if (val_a == HIGH){
  digitalWrite (led_alarm, LOW);
}


  char key = keypad.getKey();
  if (key == '#') {
    position = 0;
    setLocked(true);
  }
 
  if (key == secretCode[position]) {
    position++;
  }
 
  if (position == 3) {
    setLocked(false);
  }
  delay(50);
}
 
void setLocked(int locked)
{
  if (locked) {
    digitalWrite(led_pass, LOW);
    b=HIGH;
  }
  else {
    digitalWrite(led_pass,HIGH);
    b=LOW;
  }

}

I know what u say about delay and what it do, but in this code when enable these delay command keypad didn't response

That's because NOTHING happens during the delay() time.
Reading the keypad is something.

I don't have your hardware to test and your project needs more work anyway.
Like int b is only ever HIGH, so I think you have plans for it to change.

Anyway this compiles and I think it will take care of the delays.
If it does then it is your job to figure out how and why. :smiling_imp:

#include <Keypad.h>
#include <Password.h>
char* secretCode = "123";
int position = 0;
const byte ROWS = 4; 
const byte COLS = 3; 
const int button = 13;
const int alarm = 12;
const int led_alarm = 11;
const int del_time = A0;
const int led_pass = 10;
int b=HIGH;
int val_a;
int val_d;
char keys[ROWS][COLS] =
{
  {
    '1','2','3'      }
  ,
  {
    '4','5','6'      }
  ,
  {
    '7','8','9'      }
  ,
  {
    '*','0','#'      }
};
byte rowPins[ROWS] = {
  8, 7, 6, 5}; 
byte colPins[COLS] = {
  4, 3, 2}; 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
  pinMode(alarm, INPUT);
  pinMode(led_alarm, OUTPUT);
  pinMode(led_pass, OUTPUT);
  setLocked(true);

}

byte state;
unsigned long waitStart, waitWait;

void loop() 
{
  switch ( state )
  {
  case 0 :  
    val_a= digitalRead(alarm);
    val_d= analogRead(del_time);
    if (val_a == LOW)
    {
      //  delay (5000);
      waitStart = millis();
      waitWait = 5000UL;
      state = 10;
    }
    else // if (val_a == HIGH)... if it's not LOW, it must be HIGH
    {
      digitalWrite (led_alarm, LOW);
    }
    break;    

  case 10 :
    if ( millis() - waitStart >= waitWait )
    {
      if (b == HIGH)
      {
        digitalWrite (led_alarm, HIGH);
        // delay (5000);
        waitStart = millis();
        waitWait = 5000UL;
        state = 20;
      }
      else if (b == LOW)
      {
        digitalWrite (led_alarm, LOW);
        waitWait = 0UL;
        state = 0;
      }
    }
    break;

  case 20 :
    if ( millis() - waitStart >= waitWait )
    {
      waitWait = 0UL;
      state = 0;
    }
  }

  char key = keypad.getKey();
  if (key == '#') {
    position = 0;
    setLocked(true);
  }

  if (key == secretCode[position]) {
    position++;
  }

  if (position == 3) {
    setLocked(false);
  }
  //  delay(50);
}

void setLocked(int locked)
{
  if (locked) {
    digitalWrite(led_pass, LOW);
    b=HIGH;
  }
  else {
    digitalWrite(led_pass,HIGH);
    b=LOW;
  }

}