How to count seconds while the button is pressed?

Hi,
I’m having problem with reading the value “przycisk” (this means “button”) while the inner loop starts…

#include <LiquidCrystal.h>

int teraz = 0; // now
int drzwi; // doors
int przycisk; // button
int i, j, k, l, m;


LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

void setup() {
  lcd.begin(16, 2);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
 }

void loop() {
  if(teraz == 0) {
    przycisk = digitalRead(2);
    drzwi = digitalRead(3);
    if(drzwi == HIGH) { // the doors are open
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Drzwi otwarte."); // the doors are open
      lcd.setCursor(0, 1);
      lcd.print("Alarm rozbrojony"); // alarm disarmed
      digitalWrite(6, HIGH); // blink with green diode
      delay(500);              
      digitalWrite(6, LOW);    
      delay(500); 
      while(przycisk == LOW) { // when somebody presses the button...
        for(i=0; i<=5; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Uzbrajam..."); // arming the alarm
        lcd.setCursor(0, 1);
        lcd.print(i);
        digitalWrite(6, HIGH); // green diode ON
        delay(1000);
          if(i>=5) {
            for(j=30; j>=0; j--) {
              lcd.clear();
              lcd.setCursor(0, 0);
              lcd.print("UZBROJONO!"); // ARMED
              lcd.setCursor(0, 1);
              lcd.print(j);
              delay(1000);
              if(j==0) {
                teraz = 1;
                przycisk = digitalRead(2);
                break;
              }
            }
          }
        }
      }
    }
//rest of the code here...

The problem is with this part of code

 while(przycisk == LOW)

because I want this loop to execute only WHILE the button is pressed. If the button is pressed for 5 sec then the alarm should arm. If the button is pressed for ex. 3 seconds, then it should go out from the loop and wait again…

How to read the value “przycisk” inside this loop?

for(i=0; i<=5; i++) {

The problem is with this part of code

think the use of delay() is the real culprit to do time measurements.

The problem is that when I press the button, to countdown starts, but it doesnt matter if I'm still holding the button or not. I want the countdown to run only if I'm holding the button. If not, it should stop.

robtillaart:
think the use of delay() is the real culprit to do time measurements.

robtillaart is correct.

Guys, if I remove the delay, I can't do the countdown on the LCD...

Guys, if I remove the delay, I can't do the countdown on the LCD...

You certainly can. You just haven't bothered to try another approach. Look at the blink without delay example, and think about how YOU (not the Arduino) would change the value displayed on a chalkboard with nothing more than a clock (millis()) and a pad of paper (one or more variables where you can store a value, like the last time something happened).