พอดีกำลังทำโปรเจคเกี่ยวกับ Arduino ครับ และผมไม่ค่อยมีพื้นฐานเลยในการเขียนภาษาซีเลยไม่รู้คำสั่งบางอย่าง อันนี้โค้ดครับ ผมติดตรงที่ได้คอมเม้นไว้ครับรบกวนผู้รู้ช่วยแนะนำทีครับ
[open_code]#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;
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(customKey_one = keypad.getKey())
{
if(customKey_one != '#')
{
if (customKey_one != '*')
{
//Get password
Data_one[data_count_one] = customKey_one;
LCD.setCursor(data_count_one,0);
LCD.print(Data_one[data_count_one]);
data_count_one++;
}else
{
if (data_count_one == 4)
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("unlock bike");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
// Transfer code from Data_one to UnLockCode
// Compare LockCode & UnLock Code (if)
// Match (Unlock)- Send signal to hardware
// Not match (Ignore - Warning)
data_count_one==0; //reset counter
}else
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("num only");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
}
}
}else
{ if (data_count_one == 4)
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("lock bike");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
// Transfer code from Data_one to LockCode
// Send signal to hardware
data_count_one==0; //reset counter
}else
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("Number only");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
}
}
}//if customeKey_one
}//end loop [/close_code]
Arduino ครับช่วยที
[open_code]#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;
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(customKey_one = keypad.getKey())
{
if(customKey_one != '#')
{
if (customKey_one != '*')
{
//Get password
Data_one[data_count_one] = customKey_one;
LCD.setCursor(data_count_one,0);
LCD.print(Data_one[data_count_one]);
data_count_one++;
}else
{
if (data_count_one == 4)
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("unlock bike");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
// Transfer code from Data_one to UnLockCode
// Compare LockCode & UnLock Code (if)
// Match (Unlock)- Send signal to hardware
// Not match (Ignore - Warning)
data_count_one==0; //reset counter
}else
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("num only");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
}
}
}else
{ if (data_count_one == 4)
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("lock bike");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
// Transfer code from Data_one to LockCode
// Send signal to hardware
data_count_one==0; //reset counter
}else
{
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("Number only");
delay(500);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(Data_one);
}
}
}//if customeKey_one
}//end loop [/close_code]