สารบัญ:

ตู้เซฟ: 3 ขั้นตอน
ตู้เซฟ: 3 ขั้นตอน

วีดีโอ: ตู้เซฟ: 3 ขั้นตอน

วีดีโอ: ตู้เซฟ: 3 ขั้นตอน
วีดีโอ: วิธีการใช้งานตู้เซฟนิรภัยแบบหมุนรหัส ลีโก้ LEECO SAFE | NSB OFFICE 2024, กรกฎาคม
Anonim
ตู้เซฟ
ตู้เซฟ
ตู้เซฟ
ตู้เซฟ
ตู้เซฟ
ตู้เซฟ

นี่คือสิ่งที่ผลลัพธ์สุดท้ายของคุณควรจะเป็นหลังจากรวบรวมและอัปโหลดโค้ด

ขั้นตอนที่ 1: สิ่งที่คุณต้องการ

สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ
สิ่งที่คุณต้องการ

สายจัมเปอร์, ตัวต้านทาน 220 OHM, หน้าจอ LCD 16x2, ปุ่มกด, เซอร์โวมอเตอร์, เขียงหั่นขนม, Arduino Uno

ขั้นตอนที่ 2: รหัส

เจมส์ ชินชาย

#รวม

#รวม #รวม

ที่อยู่ int = 0; SaveTimer แบบยาวที่ไม่ได้ลงชื่อแบบคงที่ SaveDelay แบบยาวที่ไม่ได้ลงนามแบบคงที่ = (30 * 1,000);

รหัสถ่าน [10] = "1234E"; ถ่าน Str[10]; ถ่าน CodeLength = 4; int Pos = 0; บูลปลดล็อค; DisplayTimer แบบยาวที่ไม่ได้ลงชื่อแบบคงที่ DisplayDelay ยาวที่ไม่ได้ลงชื่อคงที่ = 200;

LiquidCrystal LCD (12, 11, 9, 8, 7, 6);

int buttonPin1 = 2; int buttonPin2 = 3; int buttonPin3 = 4; ปุ่ม intPin4 = 5;

int enterbutton = 10; int clearlockbutton = 13;

เซอร์โว myServo; // การตั้งค่าโปรแกรมสร้างเป็นโมฆะการตั้งค่า () {

myServo.attach(A1);

int EEPROMCodeOK = จริง; สำหรับ (Pos = 0; Pos <= (CodeLength); Pos ++) { Str [Pos] = EEPROM.read (Pos); if (!(strrchr("1123456789", Str[Pos]))) (// ไม่ใช่รหัสที่ถูกต้อง EEPROMCodeOK = false; } } Pos++; Str[Pos] = EEPROM.read (Pos); ถ้า (Str[CodeLength + 1] != 'E') EEPROMCodeOK = false; ถ้า (EEPROMCodeOK) { Str [CodeLength + 2] = '\0'; strncpy(CODE, Str, CodeLength + 1); } ClearCode(); // การตั้งค่าอินพุต pinMode (buttonPin1, INPUT_PULLUP); pinMode(buttonPin2, INPUT_PULLUP); pinMode(buttonPin3, INPUT_PULLUP); pinMode(buttonPin4, INPUT_PULLUP);

pinMode(ปุ่ม Enter, INPUT_PULLUP); pinMode (ปุ่ม clearlock, INPUT_PULLUP);

lcd.begin(16, 2); lcd.setCursor(0, 0); //การตั้งค่าข้อความ lcd.print("สวัสดี คุณเบิร์ช"); ล่าช้า (2000); lcd.clear(); lcd.setCursor(0, 0); //ตั้งค่าพร้อมท์สำหรับรหัสผ่าน lcd.print("Password:");

DisplayTimer = มิลลิวินาที () + 200; }

วงเป็นโมฆะ () {

ล็อค();

Pos = ข้อ จำกัด (Pos, 0, CodeLength); // ปุ่มอ่าน int buttonState1 = digitalRead (buttonPin1); int buttonState2 = digitalRead (buttonPin2); int buttonState3 = digitalRead (buttonPin3); int buttonState4 = digitalRead (buttonPin4);

int clButtonState = digitalRead (ปุ่ม clearlock); int enterButtonState = digitalRead (ปุ่ม Enter);

lcd.setCursor(9, 0); // ข้อกำหนดในการเปิดใช้งานหาก (buttonState1 == LOW) { Str [Pos] = '1'; ตำแหน่ง ++; Str[Pos] = '\0'; ล่าช้า (250); ในขณะที่ (digitalRead(buttonPin1) == LOW);

}

อื่นถ้า (buttonState2 == LOW) { Str [Pos] = '2'; ตำแหน่ง ++; Str[Pos] = '\0'; ล่าช้า (250); ในขณะที่ (digitalRead (buttonPin2) == ต่ำ);

}

else if (buttonState3 == LOW) { Str[Pos] = '3'; ตำแหน่ง ++; Str[Pos] = '\0'; ล่าช้า (250); ในขณะที่ (digitalRead (buttonPin3) == ต่ำ); }

else if (buttonState4 == LOW) { Str[Pos] = '4'; ตำแหน่ง ++; Str[Pos] = '\0'; ล่าช้า (250); ในขณะที่ (digitalRead (buttonPin4) == ต่ำ);

} else if (enterButtonState == LOW) { Str[Pos] = 'E'; ตำแหน่ง ++; Str[Pos] = '\0'; ล่าช้า (250); ในขณะที่ (digitalRead(buttonPin1) == LOW); ถ้า (strcmp (Str, CODE) == 0) { Unlocked = true; lcd.setCursor(0, 0); lcd.print("เข้าถึงได้"); ล่าช้า (2000); lcd.clear(); lcd.print("ปลดล็อค"); } else if (SaveTimer > millis() && (Pos + 1) == CodeLength) {

strcpy(รหัส, Str); สำหรับ (Pos = 0; Pos <= (CodeLength + 1); Pos ++) { EEPROM.write (Pos, Str [Pos]); } lcd.setCursor(0, 0); lcd.print("บันทึกรหัส:"); lcd.setCursor(0, 1); lcd.print(Str);

ปลดล็อค = จริง; }

อื่น {

lcd.clear(); lcd.print("การเข้าถึงถูกปฏิเสธ"); ล่าช้า (2000); lcd.clear(); lcd.print("รหัสผ่าน:");

} // ปลดล็อกรหัสขณะ (ปลดล็อก) { ปลดล็อก (); ถ้า (digitalRead (clearlockbutton) == LOW) { ล่าช้า (200); lcd.clear(); lcd.print("ถูกล็อค"); ล่าช้า (2000); lcd.clear(); ปลดล็อค = เท็จ; SaveTimer = มิลลิวินาที () + 30000; } }

ClearCode();

}

อื่นถ้า (clButtonState == ต่ำ) { ล่าช้า (500);

ในขณะที่ (clearlockbutton == ต่ำ); ถ้า ((มิลลิวินาที () - SaveTimer) > 4500) {

}

ClearCode();

}

ถ้า ((ยาว) (มิลลิวินาที () - DisplayTimer) >= 0) { DisplayTimer += DisplayDelay; lcd.setCursor(9, 0); lcd.print(Str); lcd.print(" ");

} }

เป็นโมฆะ ClearCode () {

ตำแหน่ง = 0; Str[Pos] = '\0'; lcd.setCursor(0, 0); lcd.print("รหัสผ่าน:"); lcd.setCursor(0, 1); lcd.print(" ");

}

ปลดล็อคเป็นโมฆะ () {

myServo.write(150);

} // ปุ่มล็อคโปรแกรม ถือเป็นโมฆะ ล็อค () {

myServo.write(50);

}

ขั้นตอนที่ 3:

เมื่อทำทุกอย่างแล้วจะออกมาเป็นแบบนี้

แนะนำ: