Blinking LEDs in sequence using class

hi all

i am trying to make a program that accepts four digit password using 3*4 keypad

the program should start with flashing LED1 and when password 1 is entered it switched this LED and blink LED2 and if password 2 is entered it switched to LED3 and so on

here is the code

#include <Keypad.h>
#include <TimedBlink.h>
 
#define Password_Lenght 5


TimedBlink led1(14);
TimedBlink led2(15);
TimedBlink led3(16);
TimedBlink led4(17);

const unsigned long PERIOD1 = 1000; 
char  buffers[4][4] = {{'1','2','3','4'},{'6','5','4','3'},{'9','8','7','6'},{'1','2','5','6'}}; // this is how to initialise a 2d array
unsigned long previousMillis[5]; //[x] = number of leds



 char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7

byte data_count = 0; 
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad
 int ledservos[4] = {14, 15, 16, 17};
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 


void setup() {
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);
  pinMode(17, OUTPUT);
  
  led1.blink(150,50);  // On for 150ms, off for 50ms
  led2.blink(150,50);
  led3.blink(150,50);  // On for 150ms, off for 50ms
  led4.blink(150,50);
  
  Serial.begin(9600);
 
  
  Serial.print("Enter Password");
  Serial.println(); 

}

void loop()
{led1.blink();
led2.blink();
led3.blink();
led4.blink();

    customKey = customKeypad.getKey();
  if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[data_count] = customKey; // store char into data array
 
    data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }

  if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master
  {
    
    Serial.print("Password is ");
for(byte i=0;i<Password_Lenght;i++)
    Serial.print(Data[i]);   

for(x = 0; x < 4; x++) {//this loop for number of passwords in the array
    for(y = 0; y < 4; y ++) {//this loop for number of characters in each of the password array
      if(strcmp(Data[y], buffers[x][y])!=0) {
        break;
    }
    }
    if(y == 4) {
      break;
    }
  }
 
  if (x < 4) {
    Serial.print(" Found at index ");
    Serial.println(x);
switch(x){
  
case 0:
led1.blinkOff();

break;
case 1:
led2.blinkOff();

break;
case 2:
led3.blinkOff();

break;
case 3:
led4.blinkOff();

break;
}
  }
  
  clearData();
  
  }
}

void clearData()
{Serial.println();  
  while(data_count !=0)
  {   // This can be used for any array size, 
    Data[data_count--] = 0; //clear array for new data
  }
}

void BlinkLed (int led, int interval, int arry){   
  
  //(long) can be omitted if you dont plan to blink led for very long time I think
   if (((long)millis() - previousMillis[arry]) >= interval){ 
   
    previousMillis[arry]= millis(); //stores the millis value in the selected array
   
    digitalWrite(led, !digitalRead(led)); //changes led state
  }
 }

now i can make the program but all LEDs start with blinking and switched off after the password is entered and got stuck at this point
plzzzz help

i have tried millis() function to be used to blink LEDs
as in the next code

#include <Keypad.h>
#include <Wire.h> 

 

#define buzzer 13
#define greenled 20
#define redled 21
#define Password_Lenght 5



unsigned long previousMillisLED14=0;
unsigned long previousMillisLED15=0;
unsigned long previousMillisLED16=0;
unsigned long previousMillisLED17=0;

// different intervals for each LED
int intervalLED14 = 500;
int intervalLED15 = 600;
int intervalLED16 = 700;
int intervalLED17 = 800;
 
// each LED gets a state varaible
boolean LED14state = false;     // the LED will turn ON in the first iteration of loop()
boolean LED15state = false;     // need to seed the light to be OFF
boolean LED16state = false;     // need to seed the light to be OFF
boolean LED17state = false;     // need to seed the light to be OFF
 

const unsigned long PERIOD1 = 1000; 
char  buffers[4][4] = {{'1','2','3','4'},{'6','5','4','3'},{'9','8','7','6'},{'1','2','5','6'}}; // this is how to initialise a 2d array
unsigned long previousMillis[5]; //[x] = number of leds


byte i,x,y;

 char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7

byte data_count = 0; 
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad
 int ledservos[4] = {14, 15, 16, 17};
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 

void setup() {
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);
  pinMode(17, OUTPUT);
  
  
  Serial.begin(9600);
  
  pinMode(buzzer, OUTPUT);
  pinMode(redled, OUTPUT);
  pinMode(greenled, OUTPUT);
  
  Serial.print("Enter Password");
  Serial.println();
   
}

void loop()
{  unsigned long currentMillis = millis();

    if ((unsigned long)(currentMillis - previousMillisLED14) >= intervalLED14) {
      LED14state = !LED14state;
      digitalWrite(14, LED14state);
      // save current time to pin 12's previousMillis
      previousMillisLED14 = currentMillis;
   } 

    customKey = customKeypad.getKey();
  if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[data_count] = customKey; // store char into data array
    
    data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }

  if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master
  {
    
    Serial.print("Password is ");
for(byte i=0;i<Password_Lenght;i++)
    Serial.print(Data[i]);   

for(x = 0; x < 4; x++) {//this loop for number of passwords in the array
    for(y = 0; y < 4; y ++) {//this loop for number of characters in each of the password array
      if(strcmp(Data[y], buffers[x][y])!=0) {
        break;
    }
    }
    if(y == 4) {
      break;
    }
  }
 
  if (x < 4) {
    Serial.print(" Found at index ");
    Serial.println(x);
  
switch(x){

case 0:
digitalWrite(14, LOW);
digitalWrite(16, LOW);
digitalWrite(17, LOW);

if ((unsigned long)(currentMillis - previousMillisLED15) >= intervalLED15) {
      LED15state = !LED15state;
      digitalWrite(15, LED15state);
      // save current time to pin 12's previousMillis
      previousMillisLED15 = currentMillis;
   }
   
break;
case 1:
digitalWrite(15, LOW);
digitalWrite(14, LOW);
digitalWrite(17, LOW);
if ((unsigned long)(currentMillis - previousMillisLED16) >= intervalLED16) {
      LED16state = !LED16state;
      digitalWrite(16, LED15state);
      // save current time to pin 12's previousMillis
      previousMillisLED16 = currentMillis;
   }
break;
case 2:
digitalWrite(15, LOW);
digitalWrite(14, LOW);
digitalWrite(16, LOW);
if ((unsigned long)(currentMillis - previousMillisLED17) >= intervalLED17) {
      LED17state = !LED17state;
      digitalWrite(17, LED17state);
      // save current time to pin 12's previousMillis
      previousMillisLED17 = currentMillis;
      
   }
break;
case 3:
digitalWrite(15, LOW);
digitalWrite(14, LOW);
digitalWrite(16, LOW);
digitalWrite(17, LOW);
break;
}
  }
  
  clearData();

  }
}

void clearData()
{Serial.println();  
  while(data_count !=0)
  {   // This can be used for any array size, 
    Data[data_count--] = 0; //clear array for new data
  }
}

but it blinks the first LED only then each of the following LEDs according to the condition got permanent on

any idea why is this happening?

i have tried the solution that adafruit suggested to use the class in code but unfortunately got the same result as the previous repl

here is the code

#include <Keypad.h>
#include <Wire.h> 


class Flasher
{
  // Class Member Variables
  // These are initialized at startup
  int ledPin;      // the number of the LED pin
  long OnTime;     // milliseconds of on-time
  long OffTime;    // milliseconds of off-time

  // These maintain the current state
  int ledState;                 // ledState used to set the LED
  unsigned long previousMillis;   // will store last time LED was updated

  // Constructor - creates a Flasher 
  // and initializes the member variables and state
  public:
  Flasher(int pin, long on, long off)
  {
  ledPin = pin;
  pinMode(ledPin, OUTPUT);     
    
  OnTime = on;
  OffTime = off;
  
  ledState = LOW; 
  previousMillis = 0;
  }

  void Update()
  {
    // check to see if it's time to change the state of the LED
    unsigned long currentMillis = millis();
     
    if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
    {
      ledState = LOW;  // Turn it off
      previousMillis = currentMillis;  // Remember the time
      digitalWrite(ledPin, ledState);  // Update the actual LED
    }
    else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
    {
      ledState = HIGH;  // turn it on
      previousMillis = currentMillis;   // Remember the time
      digitalWrite(ledPin, ledState);   // Update the actual LED
    }
  }
};


Flasher led1(14, 100, 400);
Flasher led2(15, 350, 350);
Flasher led3(16, 100, 400);
Flasher led4(17, 350, 350);

 

#define buzzer 13
#define greenled 20
#define redled 21
#define Password_Lenght 5
 

char  buffers[4][4] = {{'1','2','3','4'},{'6','5','4','3'},{'9','8','7','6'},{'1','2','5','6'}}; // this is how to initialise a 2d array
unsigned long previousMillis[5]; //[x] = number of leds


byte i,x,y;

 char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7

byte data_count = 0; 
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad
 int ledservos[4] = {14, 15, 16, 17};
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 

void setup() {
  
  Serial.begin(9600);
  
  pinMode(buzzer, OUTPUT);
  pinMode(redled, OUTPUT);
  pinMode(greenled, OUTPUT);
  
  Serial.print("Enter Password");
  Serial.println();
   
}

void loop()
{  led1.Update();
    customKey = customKeypad.getKey();
  if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[data_count] = customKey; // store char into data array
    
    data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }

  if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master
  {
    
    Serial.print("Password is ");
for(byte i=0;i<Password_Lenght;i++)
    Serial.print(Data[i]);   

for(x = 0; x < 4; x++) {//this loop for number of passwords in the array
    for(y = 0; y < 4; y ++) {//this loop for number of characters in each of the password array
      if(strcmp(Data[y], buffers[x][y])!=0) {
        break;
    }
    }
    if(y == 4) {
      break;
    }
  }
 
  if (x < 4) {
    Serial.print(" Found at index ");
    Serial.println(x);
  
switch(x){

case 0:
led2.Update();
digitalWrite(14, LOW);
digitalWrite(16, LOW);
digitalWrite(17, LOW);


   
break;
case 1:
led3.Update();
digitalWrite(15, LOW);
digitalWrite(14, LOW);
digitalWrite(17, LOW);

break;
case 2:
led4.Update();
digitalWrite(15, LOW);
digitalWrite(14, LOW);
digitalWrite(16, LOW);

break;
case 3:
digitalWrite(15, LOW);
digitalWrite(14, LOW);
digitalWrite(16, LOW);
digitalWrite(17, LOW);
break;
}
  }
  
  clearData();

  }
}

void clearData()
{Serial.println();  
  while(data_count !=0)
  {   // This can be used for any array size, 
    Data[data_count--] = 0; //clear array for new data
  }
}

any suggestion to get out of that :sob: :sob: :sob:

still trying but no clue

So, the variable 'x' controls which LED blinks, correct? And 'x' is also used to step through the loop which compares entered code to stored code?

dougp:
So, the variable 'x' controls which LED blinks, correct? And 'x' is also used to step through the loop which compares entered code to stored code?

yes x is a selector for choosing which LED to blink or to be off

is there a suggested way to achieve that so?

Print the value of 'x' immediately before:

if (x < 4) {

What is reported?

dougp:
Print the value of 'x' immediately before:

if (x < 4) {

What is reported?

same value that i get when i print it inside the condition

mestek86:
same value that i get when i print it inside the condition

Which is?

dougp:
Which is?

the index at which the password matches
for example the entered password is at index 0,1,2,3

any clue?

mestek86:
any clue?

Not yet. Maybe tomorrow.

Give this a try (compiles, limited test on LED class function but no checks of PW logic...)

#include <Keypad.h>

#define LED_ON          0
#define LED_OFF         1
#define LED_FLASH       2

#define buzzer          13
#define greenled        20
#define redled          21
#define pinLed1         14
#define pinLed2         15
#define pinLed3         16
#define pinLed4         17

#define Password_Length 4

class Flasher
{
    int ledPin;
    unsigned long OnTime;
    unsigned long OffTime;
    bool bLedOnOff;
    unsigned long timeLed;
    byte ledMode;

    // Constructor - creates a Flasher 
    // and initializes the member variables and state
    public:
        Flasher( int pin, unsigned long on, unsigned off, byte mode )
        {
            ledPin = pin;
            pinMode(ledPin, OUTPUT);     
    
            OnTime = on;
            OffTime = off;
  
            bLedOnOff = false; 
            ledMode = mode;
            timeLed = 0;
            
        }//Flasher

        void setMode( byte mode )
        {
            if( mode != LED_OFF && mode != LED_ON && mode !=LED_FLASH )
                ledMode = LED_OFF;    
            else
                ledMode = mode;
            
        }//setMode

        void Update()
        {
            unsigned long
                timeNow;
                
            switch( ledMode )
            {
                case    LED_ON:
                    digitalWrite( ledPin, HIGH );
                break;

                case    LED_OFF:
                    digitalWrite( ledPin, LOW );
            
                break;

                case    LED_FLASH:
                    timeNow = millis();
                    if( bLedOnOff == true )
                    {
                        if( (timeNow - timeLed) >= OnTime )
                        {
                            digitalWrite( ledPin, LOW );
                            bLedOnOff = false;
                            timeLed = timeNow;
                    
                        }//if
                    }//if
                    else
                    {
                        if( (timeNow - timeLed) >= OffTime )
                        {
                            digitalWrite( ledPin, HIGH );
                            bLedOnOff = true;
                            timeLed = timeNow;
                    
                        }//if
                        
                    }//else
            
                break;

                default:
                    ledMode = LED_OFF;
                    
                break;
        
            }//switch
            
        }//Update
        
};//class Flasher

Flasher
    *led1,
    *led2,
    *led3,
    *led4;

//
 
const byte ROWS = 4;
const byte COLS = 3;
const char keys[ROWS][COLS] = 
{
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
    
};

const byte 
    rowPins[ROWS] = {2,3,4,5},          //connect to the row pinouts of the keypad
    colPins[COLS] = {6,7,8};            //connect to the column pinouts of the keypad
    
const char  
    buffers[4][4] = 
    {
        {'1','2','3','4'},
        {'6','5','4','3'},
        {'9','8','7','6'},
        {'1','2','5','6'}
        
    };
    
//byte 
//    i, x, y;

char 
    Data[Password_Length]; // 6 is the number of chars it can hold + the null char = 7

byte 
    data_count = 0; 

Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 
    
void setup() 
{  
    Serial.begin(9600);

    led1 = new Flasher( pinLed1, 100, 400, LED_FLASH );
    led2 = new Flasher( pinLed2, 350, 350, LED_OFF );
    led3 = new Flasher( pinLed3, 100, 400, LED_OFF );
    led4 = new Flasher( pinLed4, 350, 350, LED_OFF );
    
    pinMode(buzzer, OUTPUT);
    pinMode(redled, OUTPUT);
    pinMode(greenled, OUTPUT);

    Serial.print("Enter Password");
    Serial.println();

    data_count = 0;

}//setup

void loop()
{
    static unsigned long
        timeTest = 0;
    static byte
        match = 0;  
    char 
        customKey;
        
    UpdateLEDs();

    customKey = customKeypad.getKey();
    
    if( customKey )
    {
        Data[data_count] = customKey;
        data_count++;

    }//if

    if( data_count == Password_Length )
    {
        Serial.print("Password entered was ");
        for( int i=0; i<Password_Length; i++ )
            Serial.print( Data[i] );   
        Serial.println("");

        match = CheckPWs();

        if( match != 0xff )
        {
            Serial.print(" Found at index ");
            Serial.println( match );

        }//if
  
        switch( match )
        {
            case    0xff:
                led1->setMode( LED_FLASH );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
                
            break;
            
            case 0:
                led1->setMode( LED_OFF );
                led2->setMode( LED_FLASH );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
   
            break;
            
            case 1:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_FLASH );
                led4->setMode( LED_OFF );

            break;
            
            case 2:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_FLASH );

            break;
            
            case 3:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
                
            break;
            
        }//switch

        //cleardata
        Serial.println();  
        data_count = 0;
        memset( Data, 0, sizeof( Data ) );
                
    }//if

}//loop

byte CheckPWs( void )
{
    bool
        chk;
    byte
        pw, ch;

    for( pw=0; pw<4; pw++ )
    {
        chk = true;
        for( ch=0; ch<4; ch ++ )
        {
            if( Data[ch] != buffers[pw][ch] ) 
                chk = false;
                
        }//for ch

        //if inner loop passes without chk being set false, pw matched
        if( chk )
            return pw;
       
    }//for pw

    //no match found; return 0xff indicating as much
    return 0xff;

}//CheckPWs

void UpdateLEDs( void )
{
    led1->Update();
    led2->Update();
    led3->Update();
    led4->Update();
    
}//UpdateLEDs

dougp:
Not yet. Maybe tomorrow.

ok waiting
thank u very much

Blackfin:
Give this a try (compiles, limited test on LED class function but no checks of PW logic...)

#include <Keypad.h>

#define LED_ON          0
#define LED_OFF        1
#define LED_FLASH      2

#define buzzer          13
#define greenled        20
#define redled          21
#define pinLed1        14
#define pinLed2        15
#define pinLed3        16
#define pinLed4        17

#define Password_Length 4

class Flasher
{
    int ledPin;
    unsigned long OnTime;
    unsigned long OffTime;
    bool bLedOnOff;
    unsigned long timeLed;
    byte ledMode;

// Constructor - creates a Flasher
    // and initializes the member variables and state
    public:
        Flasher( int pin, unsigned long on, unsigned off, byte mode )
        {
            ledPin = pin;
            pinMode(ledPin, OUTPUT);   
   
            OnTime = on;
            OffTime = off;
 
            bLedOnOff = false;
            ledMode = mode;
            timeLed = 0;
           
        }//Flasher

void setMode( byte mode )
        {
            if( mode != LED_OFF && mode != LED_ON && mode !=LED_FLASH )
                ledMode = LED_OFF;   
            else
                ledMode = mode;
           
        }//setMode

void Update()
        {
            unsigned long
                timeNow;
               
            switch( ledMode )
            {
                case    LED_ON:
                    digitalWrite( ledPin, HIGH );
                break;

case    LED_OFF:
                    digitalWrite( ledPin, LOW );
           
                break;

case    LED_FLASH:
                    timeNow = millis();
                    if( bLedOnOff == true )
                    {
                        if( (timeNow - timeLed) >= OnTime )
                        {
                            digitalWrite( ledPin, LOW );
                            bLedOnOff = false;
                            timeLed = timeNow;
                   
                        }//if
                    }//if
                    else
                    {
                        if( (timeNow - timeLed) >= OffTime )
                        {
                            digitalWrite( ledPin, HIGH );
                            bLedOnOff = true;
                            timeLed = timeNow;
                   
                        }//if
                       
                    }//else
           
                break;

default:
                    ledMode = LED_OFF;
                   
                break;
       
            }//switch
           
        }//Update
       
};//class Flasher

Flasher
    *led1,
    *led2,
    *led3,
    *led4;

//

const byte ROWS = 4;
const byte COLS = 3;
const char keys[ROWS][COLS] =
{
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
   
};

const byte
    rowPins[ROWS] = {2,3,4,5},          //connect to the row pinouts of the keypad
    colPins[COLS] = {6,7,8};            //connect to the column pinouts of the keypad
   
const char 
    buffers[4][4] =
    {
        {'1','2','3','4'},
        {'6','5','4','3'},
        {'9','8','7','6'},
        {'1','2','5','6'}
       
    };
   
//byte
//    i, x, y;

char
    Data[Password_Length]; // 6 is the number of chars it can hold + the null char = 7

byte
    data_count = 0;

Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
   
void setup()

    Serial.begin(9600);

led1 = new Flasher( pinLed1, 100, 400, LED_FLASH );
    led2 = new Flasher( pinLed2, 350, 350, LED_OFF );
    led3 = new Flasher( pinLed3, 100, 400, LED_OFF );
    led4 = new Flasher( pinLed4, 350, 350, LED_OFF );
   
    pinMode(buzzer, OUTPUT);
    pinMode(redled, OUTPUT);
    pinMode(greenled, OUTPUT);

Serial.print("Enter Password");
    Serial.println();

data_count = 0;

}//setup

void loop()
{
    static unsigned long
        timeTest = 0;
    static byte
        match = 0; 
    char
        customKey;
       
    UpdateLEDs();

customKey = customKeypad.getKey();
   
    if( customKey )
    {
        Data[data_count] = customKey;
        data_count++;

}//if

if( data_count == Password_Length )
    {
        Serial.print("Password entered was ");
        for( int i=0; i<Password_Length; i++ )
            Serial.print( Data[i] ); 
        Serial.println("");

match = CheckPWs();

if( match != 0xff )
        {
            Serial.print(" Found at index ");
            Serial.println( match );

}//if
 
        switch( match )
        {
            case    0xff:
                led1->setMode( LED_FLASH );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
               
            break;
           
            case 0:
                led1->setMode( LED_OFF );
                led2->setMode( LED_FLASH );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
 
            break;
           
            case 1:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_FLASH );
                led4->setMode( LED_OFF );

break;
           
            case 2:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_FLASH );

break;
           
            case 3:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
               
            break;
           
        }//switch

//cleardata
        Serial.println(); 
        data_count = 0;
        memset( Data, 0, sizeof( Data ) );
               
    }//if

}//loop

byte CheckPWs( void )
{
    bool
        chk;
    byte
        pw, ch;

for( pw=0; pw<4; pw++ )
    {
        chk = true;
        for( ch=0; ch<4; ch ++ )
        {
            if( Data[ch] != buffers[pw][ch] )
                chk = false;
               
        }//for ch

//if inner loop passes without chk being set false, pw matched
        if( chk )
            return pw;
     
    }//for pw

//no match found; return 0xff indicating as much
    return 0xff;

}//CheckPWs

void UpdateLEDs( void )
{
    led1->Update();
    led2->Update();
    led3->Update();
    led4->Update();
   
}//UpdateLEDs

i will test and update u

thank u very much

Blackfin:
Give this a try (compiles, limited test on LED class function but no checks of PW logic...)

#include <Keypad.h>

#define LED_ON          0
#define LED_OFF        1
#define LED_FLASH      2

#define buzzer          13
#define greenled        20
#define redled          21
#define pinLed1        14
#define pinLed2        15
#define pinLed3        16
#define pinLed4        17

#define Password_Length 4

class Flasher
{
    int ledPin;
    unsigned long OnTime;
    unsigned long OffTime;
    bool bLedOnOff;
    unsigned long timeLed;
    byte ledMode;

// Constructor - creates a Flasher
    // and initializes the member variables and state
    public:
        Flasher( int pin, unsigned long on, unsigned off, byte mode )
        {
            ledPin = pin;
            pinMode(ledPin, OUTPUT);   
   
            OnTime = on;
            OffTime = off;
 
            bLedOnOff = false;
            ledMode = mode;
            timeLed = 0;
           
        }//Flasher

void setMode( byte mode )
        {
            if( mode != LED_OFF && mode != LED_ON && mode !=LED_FLASH )
                ledMode = LED_OFF;   
            else
                ledMode = mode;
           
        }//setMode

void Update()
        {
            unsigned long
                timeNow;
               
            switch( ledMode )
            {
                case    LED_ON:
                    digitalWrite( ledPin, HIGH );
                break;

case    LED_OFF:
                    digitalWrite( ledPin, LOW );
           
                break;

case    LED_FLASH:
                    timeNow = millis();
                    if( bLedOnOff == true )
                    {
                        if( (timeNow - timeLed) >= OnTime )
                        {
                            digitalWrite( ledPin, LOW );
                            bLedOnOff = false;
                            timeLed = timeNow;
                   
                        }//if
                    }//if
                    else
                    {
                        if( (timeNow - timeLed) >= OffTime )
                        {
                            digitalWrite( ledPin, HIGH );
                            bLedOnOff = true;
                            timeLed = timeNow;
                   
                        }//if
                       
                    }//else
           
                break;

default:
                    ledMode = LED_OFF;
                   
                break;
       
            }//switch
           
        }//Update
       
};//class Flasher

Flasher
    *led1,
    *led2,
    *led3,
    *led4;

//

const byte ROWS = 4;
const byte COLS = 3;
const char keys[ROWS][COLS] =
{
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
   
};

const byte
    rowPins[ROWS] = {2,3,4,5},          //connect to the row pinouts of the keypad
    colPins[COLS] = {6,7,8};            //connect to the column pinouts of the keypad
   
const char 
    buffers[4][4] =
    {
        {'1','2','3','4'},
        {'6','5','4','3'},
        {'9','8','7','6'},
        {'1','2','5','6'}
       
    };
   
//byte
//    i, x, y;

char
    Data[Password_Length]; // 6 is the number of chars it can hold + the null char = 7

byte
    data_count = 0;

Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
   
void setup()

    Serial.begin(9600);

led1 = new Flasher( pinLed1, 100, 400, LED_FLASH );
    led2 = new Flasher( pinLed2, 350, 350, LED_OFF );
    led3 = new Flasher( pinLed3, 100, 400, LED_OFF );
    led4 = new Flasher( pinLed4, 350, 350, LED_OFF );
   
    pinMode(buzzer, OUTPUT);
    pinMode(redled, OUTPUT);
    pinMode(greenled, OUTPUT);

Serial.print("Enter Password");
    Serial.println();

data_count = 0;

}//setup

void loop()
{
    static unsigned long
        timeTest = 0;
    static byte
        match = 0; 
    char
        customKey;
       
    UpdateLEDs();

customKey = customKeypad.getKey();
   
    if( customKey )
    {
        Data[data_count] = customKey;
        data_count++;

}//if

if( data_count == Password_Length )
    {
        Serial.print("Password entered was ");
        for( int i=0; i<Password_Length; i++ )
            Serial.print( Data[i] ); 
        Serial.println("");

match = CheckPWs();

if( match != 0xff )
        {
            Serial.print(" Found at index ");
            Serial.println( match );

}//if
 
        switch( match )
        {
            case    0xff:
                led1->setMode( LED_FLASH );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
               
            break;
           
            case 0:
                led1->setMode( LED_OFF );
                led2->setMode( LED_FLASH );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
 
            break;
           
            case 1:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_FLASH );
                led4->setMode( LED_OFF );

break;
           
            case 2:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_FLASH );

break;
           
            case 3:
                led1->setMode( LED_OFF );
                led2->setMode( LED_OFF );
                led3->setMode( LED_OFF );
                led4->setMode( LED_OFF );
               
            break;
           
        }//switch

//cleardata
        Serial.println(); 
        data_count = 0;
        memset( Data, 0, sizeof( Data ) );
               
    }//if

}//loop

byte CheckPWs( void )
{
    bool
        chk;
    byte
        pw, ch;

for( pw=0; pw<4; pw++ )
    {
        chk = true;
        for( ch=0; ch<4; ch ++ )
        {
            if( Data[ch] != buffers[pw][ch] )
                chk = false;
               
        }//for ch

//if inner loop passes without chk being set false, pw matched
        if( chk )
            return pw;
     
    }//for pw

//no match found; return 0xff indicating as much
    return 0xff;

}//CheckPWs

void UpdateLEDs( void )
{
    led1->Update();
    led2->Update();
    led3->Update();
    led4->Update();
   
}//UpdateLEDs

Greeeat

it is working perfectly

Thank u very much