4x4 keypad lcd pir alarm

HI i have this code ive found on the internet it works fine but i want to make it work as an alarm when you activate the sensor the alarm should give you some time for you to deactivate it before the buzzer goes on what should i change?

FHCG7TIIT22USH3.ino (4.13 KB)

What have you tried?

ive tried delayin the buzzer but it doesnt let me type the code until the leds stop blinking

You'll have to do it without using delay. See the Blink Without Delay example and any of the thousands of tutorials about it for some inspiration.

how could i apply that to this code could you help? thanks

The below is a non-blocking delay function.

/*
  non blocking delay
  In:
    duration of delay
  Returns:
    false if delay is in progress, else true
*/
bool waitALittle(unsigned long duration)
{
  static unsigned long startTime = 0;

  // if no start time set, 'start' the delay
  if (startTime == 0)
  {
    startTime = millis();
    return false;
  }

  // check if delay has lapsed
  if (millis() - startTime >= duration)
  {
    startTime = 0;
    return true;
  }

  return false;
}

The code above remembers the start time of the delay. Call it repeatedly; once the delay has lapsed, it will return true and you can act on that as shown below. Note that if you have a need for 2 different 'delays' at the same time (e.g. flash a led every second and buzz every 2 seconds), you will need a second function (e.g. waitALittle2) that can be a literal copy of waitALittle. If you need a third 'delay' at the same time, it's time to think of a different approach.

In other functions, you can use it like

void loop()
{
  if(waitALittle(10000) == true)
  {
    // do something, e.g. blink a led
    digitalWrite(13, !digitalRead(13));
  }

  // read sensor
  ...
  ...
  // read keypad
  ...
  ...
  // do other stuff
  ...
  ...
}

You will need additional logic to make this work exactly as you want.

If you understand the above, I think it's easy to see how Blink-Without-Delay works.