Mục lục:

Két an toàn: 3 bước
Két an toàn: 3 bước

Video: Két an toàn: 3 bước

Video: Két an toàn: 3 bước
Video: Phân loại hồ sơ Thiết kế 1 bước 2 bước 3 bước 2024, Tháng bảy
Anonim
Két an toàn
Két an toàn
Két an toàn
Két an toàn
Két an toàn
Két an toàn

Đây là kết quả cuối cùng của bạn sau khi tập hợp nó lại với nhau và tải lên mã.

Bước 1: Những thứ bạn sẽ cần

Những thứ bạn sẽ cần
Những thứ bạn sẽ cần
Những thứ bạn sẽ cần
Những thứ bạn sẽ cần
Những thứ bạn sẽ cần
Những thứ bạn sẽ cần
Những thứ bạn sẽ cần
Những thứ bạn sẽ cần

Dây nhảy, điện trở 220 OHM, Màn hình LCD 16x2, Nút đẩy, Động cơ Servo, Bảng mạch, Arduino Uno.

Bước 2: Mã

James chinchay

#bao gồm

#include #include

địa chỉ int = 0; static unsigned long SaveTimer; static unsigned long SaveDelay = (30 * 1000);

char CODE [10] = "1234E"; char Str [10]; char CodeLength = 4; int Pos = 0; bool Đã mở khóa; static unsigned long DisplayTimer; static unsigned long DisplayDelay = 200;

Màn hình LCD LiquidCrystal (12, 11, 9, 8, 7, 6);

int buttonPin1 = 2; int buttonPin2 = 3; int buttonPin3 = 4; int buttonPin4 = 5;

int enterbutton = 10; int clearlockbutton = 13;

Servo myServo; // thiết lập chương trình xây dựng void setup () {

myServo.attach (A1);

int EEPROMCodeOK = true; for (Pos = 0; Pos <= (CodeLength); Pos ++) {Str [Pos] = EEPROM.read (Pos); if (! (strrchr ("1123456789", Str [Pos])))) {// không phải là mã hợp lệ EEPROMCodeOK = false; }} Pos ++; Str [Pos] = EEPROM.read (Pos); if (Str [CodeLength + 1]! = 'E') EEPROMCodeOK = false; if (EEPROMCodeOK) {Str [CodeLength + 2] = '\ 0'; strncpy (CODE, Str, CodeLength + 1); } ClearCode (); // thiết lập đầu vào pinMode (buttonPin1, INPUT_PULLUP); pinMode (buttonPin2, INPUT_PULLUP); pinMode (buttonPin3, INPUT_PULLUP); pinMode (buttonPin4, INPUT_PULLUP);

pinMode (enterbutton, INPUT_PULLUP); pinMode (clearlockbutton, INPUT_PULLUP);

lcd.begin (16, 2); lcd.setCursor (0, 0); // thiết lập tin nhắn lcd.print ("Xin chào Mr Birch"); chậm trễ (2000); lcd.clear (); lcd.setCursor (0, 0); // thiết lập lời nhắc nhập mật khẩu lcd.print ("Mật khẩu:");

DisplayTimer = millis () + 200; }

void loop () {

Khoa();

Pos = ràng buộc (Pos, 0, CodeLength); // đọc các nút int buttonState1 = digitalRead (buttonPin1); int buttonState2 = digitalRead (buttonPin2); int buttonState3 = digitalRead (buttonPin3); int buttonState4 = digitalRead (buttonPin4);

int clButtonState = digitalRead (clearlockbutton); int enterButtonState = digitalRead (enterbutton);

lcd.setCursor (9, 0); // các yêu cầu để kích hoạt if (buttonState1 == LOW) {Str [Pos] = '1'; Pos ++; Str [Pos] = '\ 0'; chậm trễ (250); while (digitalRead (buttonPin1) == LOW);

}

else if (buttonState2 == LOW) {Str [Pos] = '2'; Pos ++; Str [Pos] = '\ 0'; chậm trễ (250); while (digitalRead (buttonPin2) == LOW);

}

else if (buttonState3 == LOW) {Str [Pos] = '3'; Pos ++; Str [Pos] = '\ 0'; chậm trễ (250); while (digitalRead (buttonPin3) == LOW); }

else if (buttonState4 == LOW) {Str [Pos] = '4'; Pos ++; Str [Pos] = '\ 0'; chậm trễ (250); while (digitalRead (buttonPin4) == LOW);

} else if (enterButtonState == LOW) {Str [Pos] = 'E'; Pos ++; Str [Pos] = '\ 0'; chậm trễ (250); while (digitalRead (buttonPin1) == LOW); if (strcmp (Str, CODE) == 0) {Đã mở khóa = true; lcd.setCursor (0, 0); lcd.print ("Đã cấp quyền truy cập"); chậm trễ (2000); lcd.clear (); lcd.print ("Đã mở khóa"); } else if (SaveTimer> millis () && (Pos + 1) == CodeLength) {

strcpy (CODE, Str); for (Pos = 0; Pos <= (CodeLength + 1); Pos ++) {EEPROM.write (Pos, Str [Pos]); } lcd.setCursor (0, 0); lcd.print ("Mã Lưu:"); lcd.setCursor (0, 1); lcd.print (Str);

Đã mở khóa = true; }

khác {

lcd.clear (); lcd.print ("Truy cập Bị Từ chối."); chậm trễ (2000); lcd.clear (); lcd.print ("Mật khẩu:");

} // mã mở khóa while (Đã mở khóa) {Unlock (); if (digitalRead (clearlockbutton) == LOW) {delay (200); lcd.clear (); lcd.print ("Đã khóa"); chậm trễ (2000); lcd.clear (); Đã mở khóa = false; SaveTimer = millis () + 30000; }}

ClearCode ();

}

else if (clButtonState == LOW) {delay (500);

while (clearlockbutton == LOW); if ((millis () - SaveTimer)> 4500) {

}

ClearCode ();

}

if ((long) (millis () - DisplayTimer)> = 0) {DisplayTimer + = DisplayDelay; lcd.setCursor (9, 0); lcd.print (Str); lcd.print ("");

} }

void ClearCode () {

Vị trí = 0; Str [Pos] = '\ 0'; lcd.setCursor (0, 0); lcd.print ("Mật khẩu:"); lcd.setCursor (0, 1); lcd.print ("");

}

void Unlock () {

myServo.write (150);

} // nút khóa chương trình void Lock () {

myServo.write (50);

}

Bước 3:

khi hoàn thành mọi thứ nó sẽ trông như thế này.

Đề xuất: