Talaan ng mga Nilalaman:
2025 May -akda: John Day | [email protected]. Huling binago: 2025-01-13 06:58
Ito ang dapat mong maging wakas na resulta pagkatapos na magkasama ito at mai-upload ang code.
Hakbang 1: Mga Bagay na Kakailanganin Mo
Jumper Wires, 220 OHM resistor, 16x2 LCD Screen, Push Buttons, Servo Motor, Breadboard, Arduino Uno.
Hakbang 2: Code
James chinchay
# isama
# isama ang # isama
int address = 0; static unsigned mahabang SaveTimer; static unsigned mahabang SaveDelay = (30 * 1000);
char CODE [10] = "1234E"; char Str [10]; char CodeLength = 4; int Pos = 0; bool Na-unlock; static unsigned mahabang DisplayTimer; static unsigned mahabang DisplayDelay = 200;
LiquidCrystal lcd (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; // setting up the build program void setup () {
myServo.attach (A1);
int EEPROMCodeOK = totoo; para sa (Pos = 0; Pos <= (CodeLength); Pos ++) {Str [Pos] = EEPROM.read (Pos); kung (! (strrchr ("1123456789", Str [Pos]))) {// hindi isang wastong code EEPROMCodeOK = false; }} Pos ++; Str [Pos] = EEPROM.read (Pos); kung (Str [CodeLength + 1]! = 'E') EEPROMCodeOK = false; kung (EEPROMCodeOK) {Str [CodeLength + 2] = '\ 0'; strncpy (CODE, Str, CodeLength + 1); } ClearCode (); // setting up inputs 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); // setting up messaged lcd.print ("Hello Mr Birch"); pagkaantala (2000); lcd.clear (); lcd.setCursor (0, 0); // prompt ng pag-set up para sa password lcd.print ("Password:");
DisplayTimer = millis () + 200; }
void loop () {
Lock ();
Pos = pipigilan (Pos, 0, Haba ng Code); // read button 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); // mga kinakailangan upang buhayin kung (buttonState1 == LOW) {Str [Pos] = '1'; Pos ++; Str [Pos] = '\ 0'; pagkaantala (250); habang (digitalRead (buttonPin1) == LOW);
}
kung hindi man (buttonState2 == LOW) {Str [Pos] = '2'; Pos ++; Str [Pos] = '\ 0'; pagkaantala (250); habang (digitalRead (buttonPin2) == LOW);
}
kung hindi man kung (buttonState3 == LOW) {Str [Pos] = '3'; Pos ++; Str [Pos] = '\ 0'; pagkaantala (250); habang (digitalRead (buttonPin3) == LOW); }
kung hindi man kung (buttonState4 == LOW) {Str [Pos] = '4'; Pos ++; Str [Pos] = '\ 0'; pagkaantala (250); habang (digitalRead (buttonPin4) == LOW);
} iba pa kung (enterbuttonState == LOW) {Str [Pos] = 'E'; Pos ++; Str [Pos] = '\ 0'; pagkaantala (250); habang (digitalRead (buttonPin1) == LOW); kung (strcmp (Str, CODE) == 0) {Unlocked = true; lcd.setCursor (0, 0); lcd.print ("Access Granted"); pagkaantala (2000); lcd.clear (); lcd.print ("Unlocked"); } iba pa kung (SaveTimer> millis () && (Pos + 1) == CodeLength) {
strcpy (CODE, Str); para sa (Pos = 0; Pos <= (CodeLength + 1); Pos ++) {EEPROM.write (Pos, Str [Pos]); } lcd.setCursor (0, 0); lcd.print ("Saving Code:"); lcd.setCursor (0, 1); lcd.print (Str);
Na-unlock = totoo; }
iba pa {
lcd.clear (); lcd.print ("Access Denied."); pagkaantala (2000); lcd.clear (); lcd.print ("Password:");
} // unlocking code habang (Na-unlock) {Unlock (); kung (digitalRead (clearlockbutton) == LOW) {pagkaantala (200); lcd.clear (); lcd.print ("Naka-lock"); pagkaantala (2000); lcd.clear (); Na-unlock = maling; SaveTimer = millis () + 30000; }}
ClearCode ();
}
kung hindi man kung (clButtonState == LOW) {pagkaantala (500);
habang (clearlockbutton == LOW); kung ((millis () - SaveTimer)> 4500) {
}
ClearCode ();
}
kung ((haba) (millis () - DisplayTimer)> = 0) {DisplayTimer + = DisplayDelay; lcd.setCursor (9, 0); lcd.print (Str); lcd.print ("");
} }
walang bisa ang ClearCode () {
Pos = 0; Str [Pos] = '\ 0'; lcd.setCursor (0, 0); lcd.print ("Password:"); lcd.setCursor (0, 1); lcd.print ("");
}
walang bisa ang I-unlock () {
myServo.write (150);
} // pindutan ng pag-lock ng programa na walang bisa Lock () {
myServo.write (50);
}
Hakbang 3:
kapag tapos lahat dapat ganito ang hitsura.