วัตถุประสงค์ คือ ต้องการเปลี่ยน ค่า password ใหม่ ได้ตามต้องการ โดยบันทึกเอาไว้ใน EEPROM แล้วดึง มาใช้เป็นค่า Password ใหม่ แต่ตามโค๊ด ผมสามารถใช้ password ได้แต่ 2514 ตามที่ EEPROM.write แต่ จะเปลี่ยนเป็นpaaswotd แบบอิสระต้องปรับเปรียนตำแหน่งไหน
#include <Password.h>
#include <EEPROM.h>
byte a;
byte b;
byte c;
byte d;
int i=0;
char newPassword[5]= " " ;
Password password = Password(newPassword);
byte currentLength = 0;
void setup()
{
Serial.begin(9600);
//Serial.print("Enter password = ");
a = EEPROM.read(0);
delay(100);
b = EEPROM.read(1);
delay(100);
c = EEPROM.read(2);
delay(100);
d = EEPROM.read(3);
delay(100);
for (int ii=0; ii<4; ii++)
{
newPassword[ii]=EEPROM.read(0+ii);
delay(5);
Serial.print(newPassword[ii],'BYTE');
}
}
void loop()
{
if (Serial.available())
{
char input = Serial.read();
switch (input)
{
case '*': //reset password
password.reset();
currentLength = 0;
Serial.println("\tPassword is reset!");
break;
case '#': //evaluate password
if (password.evaluate())
{
Serial.println("\tOK Password Correct");
password.reset();
currentLength = 0;
}
else
{
Serial.println("\tNO Password Did Not");
password.reset();
currentLength = 0;
Serial.println("\tPassword is reset!");
}
break;
case 'n': // New Pasword
delay(100);
{
EEPROM.write(0,'2');
delay(100);
EEPROM.write(1,'5');
delay(100);
EEPROM.write(2,'1');
delay(100);
EEPROM.write(3,'4');
delay(100);
break;
default:
password << input;
currentLength++;
}
}
}
}
ใช่ที่เคยถามที่ลิงค์นี้มั้ยครับ http://www.arduinoall.com/webboard/viewtopic/145
ต้องลองทำทีละขั้นครับ ตามที่ได้แนะนำไปแล้ว แล้วสรุปความรู้มาทำเป็นเมนูครับ ต้องลองเยอะ ๆครับ