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