INHOUDSOPGAWE:

Kluis: 3 stappe
Kluis: 3 stappe

Video: Kluis: 3 stappe

Video: Kluis: 3 stappe
Video: Основные ошибки при возведении перегородок из газобетона #5 2024, November
Anonim
Kluis
Kluis
Kluis
Kluis
Kluis
Kluis

Dit is wat u eindresultaat moet wees nadat u dit saamgestel en die kode opgelaai het.

Stap 1: Dinge wat u benodig

Dinge wat u benodig
Dinge wat u benodig
Dinge wat u benodig
Dinge wat u benodig
Dinge wat u benodig
Dinge wat u benodig
Dinge wat u benodig
Dinge wat u benodig

Springdrade, 220 OHM -weerstand, 16x2 LCD -skerm, drukknoppe, servomotor, broodbord, Arduino Uno.

Stap 2: Kode

James chinchay

#insluit

#include #include

int adres = 0; statiese ongetekende lang SaveTimer; statiese ongetekende lang SaveDelay = (30 * 1000);

char CODE [10] = "1234E"; char Str [10]; char CodeLength = 4; int Pos = 0; bool Ontsluit; statiese ongetekende lang DisplayTimer; statiese ongetekende lang DisplayDelay = 200;

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

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

int enter -knoppie = 10; int clearlock -knoppie = 13;

Servo myServo; // die opstel van die konstruksieprogram leemte -opstelling () {

myServo.attach (A1);

int EEPROMCodeOK = waar; vir (Pos = 0; Pos <= (CodeLength); Pos ++) {Str [Pos] = EEPROM.read (Pos); as (! (strrchr ("1123456789", Str [Pos]))) {// nie 'n geldige kode EEPROMCodeOK = false; }} Pos ++; Str [Pos] = EEPROM.read (Pos); as (Str [CodeLength + 1]! = 'E') EEPROMCodeOK = false; as (EEPROMCodeOK) {Str [CodeLength + 2] = '\ 0'; strncpy (CODE, Str, CodeLength + 1); } ClearCode (); // die opstel van insette pinMode (buttonPin1, INPUT_PULLUP); pinMode (buttonPin2, INPUT_PULLUP); pinMode (buttonPin3, INPUT_PULLUP); pinMode (buttonPin4, INPUT_PULLUP);

pinMode (enterbutton, INPUT_PULLUP); pinMode (clearlock -knoppie, INPUT_PULLUP);

lcd.begin (16, 2); lcd.setCursor (0, 0); // die opstel van lcd.print ("Hallo meneer Birch"); vertraging (2000); lcd.clear (); lcd.setCursor (0, 0); // die opstel van prompt vir wagwoord lcd.print ("Wagwoord:");

DisplayTimer = millis () + 200; }

leemte -lus () {

Slot ();

Pos = beperking (Pos, 0, CodeLength); // lees knoppies 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); // vereistes om te aktiveer as (buttonState1 == LOW) {Str [Pos] = '1'; Pos ++; Str [Pos] = '\ 0'; vertraging (250); terwyl (digitalRead (buttonPin1) == LOW);

}

anders as (buttonState2 == LOW) {Str [Pos] = '2'; Pos ++; Str [Pos] = '\ 0'; vertraging (250); terwyl (digitalRead (buttonPin2) == LOW);

}

anders as (buttonState3 == LOW) {Str [Pos] = '3'; Pos ++; Str [Pos] = '\ 0'; vertraging (250); terwyl (digitalRead (buttonPin3) == LOW); }

anders as (buttonState4 == LOW) {Str [Pos] = '4'; Pos ++; Str [Pos] = '\ 0'; vertraging (250); terwyl (digitalRead (buttonPin4) == LOW);

} anders as (enterButtonState == LOW) {Str [Pos] = 'E'; Pos ++; Str [Pos] = '\ 0'; vertraging (250); terwyl (digitalRead (buttonPin1) == LOW); if (strcmp (Str, CODE) == 0) {Ontsluit = waar; lcd.setCursor (0, 0); lcd.print ("Toegang verleen"); vertraging (2000); lcd.clear (); lcd.print ("Ontsluit"); } anders as (SaveTimer> millis () && (Pos + 1) == CodeLength) {

strcpy (KODE, Str); vir (Pos = 0; Pos <= (CodeLength+1); Pos ++) {EEPROM.write (Pos, Str [Pos]); } lcd.setCursor (0, 0); lcd.print ("Spaarkode:"); lcd.setCursor (0, 1); lcd.print (Str);

Ontsluit = waar; }

anders {

lcd.clear (); lcd.print ("Toegang geweier."); vertraging (2000); lcd.clear (); lcd.print ("Wagwoord:");

} // ontsluit kode terwyl (Ontsluit) {Ontsluit (); if (digitalRead (clearlockbutton) == LOW) {vertraging (200); lcd.clear (); lcd.print ("Gesluit"); vertraging (2000); lcd.clear (); Ontsluit = vals; SaveTimer = millis () + 30000; }}

ClearCode ();

}

anders as (clButtonState == LOW) {vertraging (500);

terwyl (clearlockbutton == LOW); as ((millis () - SaveTimer)> 4500) {

}

ClearCode ();

}

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

} }

nietig ClearCode () {

Pos = 0; Str [Pos] = '\ 0'; lcd.setCursor (0, 0); lcd.print ("Wagwoord:"); lcd.setCursor (0, 1); lcd.print ("");

}

nietig ontsluit () {

myServo.write (150);

} // program se sluitknoppie leeg () {

myServo.write (50);

}

Stap 3:

as alles klaar is, moet dit so lyk.

Aanbeveel: