นี่คือโค้ดครับ ผมได้ simulator ข้อผิดพลาดเอาไว้ตามลิงค์นี้น่ะครับ http://youtu.be/X2J6l6tiEx4
คือผมไม่ทราบว่ามันต้องมีเงื่อนไขอะไรอีกรึเปล่า ตอนใส่รหัสครั้งที่สองเพื่อที่จะปล็คล็อค
และถ้าผมจะกำหนดเงื่อนไขให้การใส่รหัสนั้นต้องเป็นเฉพาะตัวเลขเท่านั้น และเงื่อนไขการกดล็อคและปล็ดล็อคต้องเป็นตัวเลขสี่หลักเท่านั้นไม่ทราบว่าต้องทำยังไงครับ
#include <Keypad.h>
#include <LiquidCrystal.h>
#define Password_Lenght 4 // เก็บสี่หลัก
LiquidCrystal LCD(A0, A1, A2, A3, A4, A5);
char Data_one[Password_Lenght];
char Data_two[Password_Lenght];
byte maxPasswordLength = 4;
byte currentPasswordLength = 0;
byte data_count_one = 0,data_count_two = 0, master_count = 0;
boolean Pass_is_good1 = false;
boolean Pass_is_good2 = false;
boolean Pass_is_good3 = false;
boolean Pass_is_good4 = false;
char customKey_one,customKey_two;
int state = 0;
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] = {10, 9, 8, 7};
byte colPins[COLS] = {13, 12, 11};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
LCD.begin(16, 2);
}
void lock()
{
}
void unlock()
{
}
void loop()
{
if(state == 0)
{
while(1)
{
customKey_one = keypad.getKey();
if (customKey_one)
{
if(customKey_one == '#')
{
break;
}
Data_one[data_count_one] = customKey_one;
LCD.setCursor(data_count_one,1);
LCD.print(Data_one[data_count_one]);
data_count_one++;
}
}
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("lock");
lock();
state = 1;
}
else
{
while(1)
{
customKey_two = keypad.getKey();
if (customKey_two)
{
if(customKey_two == '#')
{
break;
}
Data_two[data_count_two] = customKey_two;
LCD.setCursor(data_count_two,1);
LCD.print(Data_two[data_count_two]);
data_count_two++;
}
}
LCD.clear();
LCD.setCursor(0, 0);
if(Data_two[0] == Data_one[0])
{
Pass_is_good1 = true;
}
else { Pass_is_good1 = false; }
if(Data_two[1] == Data_one[1])
{
Pass_is_good2 = true;
}
else { Pass_is_good2 = false; }
if(Data_two[2] == Data_one[2])
{
Pass_is_good3 = true;
}
else { Pass_is_good3 = false; }
if(Data_two[3] == Data_one[3])
{
Pass_is_good4 = true;
}
else { Pass_is_good4 = false; }
if( (Pass_is_good1 == true)&&(Pass_is_good2 == true)&&(Pass_is_good3 == true)&&(Pass_is_good4 == true) )
{
LCD.print("Unlock");
unlock();
state = 0;
}
else
{
LCD.print("lock");
lock();
state = 0;
}
}
}
หน้าที่เข้าชม | 7,125,785 ครั้ง |
ผู้ชมทั้งหมด | 2,822,683 ครั้ง |
เปิดร้าน | 15 ก.ย. 2557 |
ร้านค้าอัพเดท | 6 ก.ย. 2568 |