2025 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2025-01-13 06:58
Bu sizning yakuniy natijangiz, uni birlashtirish va kodni yuklashdan keyin bo'lishi kerak.
1 -qadam: Sizga kerak bo'lgan narsalar
Jumper simlari, 220 OHM qarshilik, 16x2 LCD displey, tugmachalar, Servo dvigateli, breadboard, Arduino Uno.
2 -qadam: kod
Jeyms Chinchay
#qo'shing
#qo'shing #qo'shing
int manzili = 0; statik imzosiz uzoq SaveTimer; statik belgisiz uzun SaveDelay = (30 * 1000);
char kodi [10] = "1234E"; char Str [10]; char CodeLength = 4; int Pos = 0; bool qulfdan chiqarilgan; statik belgisiz uzun DisplayTimer; statik belgisiz uzun DisplayDelay = 200;
LiquidCrystal lcd (12, 11, 9, 8, 7, 6);
int tugmasiPin1 = 2; int tugmasiPin2 = 3; int tugmasiPin3 = 4; int tugmasiPin4 = 5;
int enterbutton = 10; int clearlockbutton = 13;
MyServo xizmat ko'rsatish; // tuzilish dasturini sozlash void setup () {
myServo.attach (A1);
int EEPROMCodeOK = rost; uchun (Pos = 0; Pos <= (CodeLength); Pos ++) {Str [Pos] = EEPROM.read (Pos); if (! (strrchr ("1123456789", Str [Pos]))) {// haqiqiy kod emas EEPROMCodeOK = false; }} Pos ++; Str [Pos] = EEPROM.read (Pos); if (Str [CodeLength + 1]! = 'E') EEPROMCodeOK = noto'g'ri; if (EEPROMCodeOK) {Str [CodeLength + 2] = '\ 0'; strncpy (CODE, Str, CodeLength + 1); } ClearCode (); // pinMode kirishini sozlash (buttonPin1, INPUT_PULLUP); pinMod (tugmaPin2, INPUT_PULLUP); pinMod (tugmaPin3, INPUT_PULLUP); pinMod (tugmaPin4, INPUT_PULLUP);
pinMode (kiritish tugmasi, INPUT_PULLUP); pinMod (o'chirish tugmasi, INPUT_PULLUP);
lcd.begin (16, 2); lcd.setCursor (0, 0); // xabar yuborilgan lcd.print -ni sozlash ("Salom janob Birch"); kechikish (2000); lcd.clear (); lcd.setCursor (0, 0); // lcd.print parolini so'rashni sozlash ("Parol:");
DisplayTimer = millis () + 200; }
void loop () {
Qulf ();
Pos = cheklash (Pos, 0, CodeLength); // o'qish tugmalari 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); // faollashtirish talablari, agar (buttonState1 == LOW) {Str [Pos] = '1'; Pos ++; Str [Pos] = '\ 0'; kechikish (250); while (digitalRead (buttonPin1) == LOW);
}
else if (buttonState2 == LOW) {Str [Pos] = '2'; Pos ++; Str [Pos] = '\ 0'; kechikish (250); while (digitalRead (buttonPin2) == LOW);
}
else if (buttonState3 == LOW) {Str [Pos] = '3'; Pos ++; Str [Pos] = '\ 0'; kechikish (250); while (digitalRead (buttonPin3) == LOW); }
else if (buttonState4 == LOW) {Str [Pos] = '4'; Pos ++; Str [Pos] = '\ 0'; kechikish (250); while (digitalRead (buttonPin4) == LOW);
} if if (enterButtonState == LOW) {Str [Pos] = 'E'; Pos ++; Str [Pos] = '\ 0'; kechikish (250); while (digitalRead (buttonPin1) == LOW); if (strcmp (Str, CODE) == 0) {Unlocked = true; lcd.setCursor (0, 0); lcd.print ("Kirish huquqi berilgan"); kechikish (2000); lcd.clear (); lcd.print ("Qulfdan chiqarilgan"); } if if (SaveTimer> millis () && (Pos + 1) == CodeLength) {
strcpy (KOD, Str); uchun (Pos = 0; Pos <= (CodeLength+1); Pos ++) {EEPROM.write (Pos, Str [Pos]); } lcd.setCursor (0, 0); lcd.print ("Saqlash kodi:"); lcd.setCursor (0, 1); lcd.print (Str);
Qulfdan chiqarilgan = rost; }
boshqa {
lcd.clear (); lcd.print ("Kirish taqiqlangan."); kechikish (2000); lcd.clear (); lcd.print ("Parol:");
} // qulfni ochish paytida kod (qulfdan chiqarilgan) {Qulfni ochish (); if (digitalRead (clearlockbutton) == LOW) {kechiktirish (200); lcd.clear (); lcd.print ("Qulflangan"); kechikish (2000); lcd.clear (); Qulfdan chiqarilgan = noto'g'ri; SaveTimer = millis () + 30000; }}
ClearCode ();
}
else if (clButtonState == LOW) {kechiktirish (500);
while (clearlockbutton == LOW); agar ((millis () - SaveTimer)> 4500) {
}
ClearCode ();
}
if ((uzun) (millis () - DisplayTimer)> = 0) {DisplayTimer += DisplayDelay; lcd.setCursor (9, 0); lcd.print (Str); lcd.print ("");
} }
void ClearCode () {
Pos = 0; Str [Pos] = '\ 0'; lcd.setCursor (0, 0); lcd.print ("Parol:"); lcd.setCursor (0, 1); lcd.print ("");
}
bo'sh qulfni ochish () {
myServo.write (150);
} // dasturni qulflash tugmasi void Lock () {
myServo.write (50);
}
3 -qadam:
hamma narsa bajarilgach, shunday ko'rinishi kerak.