Sustav kontrole pristupa prostoru ostvaren je unosom numeričke lozinke s membranske tipkovnice. Ovisno o ispravnosti lozinke servo motor otključava vrata. Omogućeno je i mijenjanje same lozinke kao i prikaz datuma i vremena na LCD-u.

Dependencies:   mbed Servo RGB-LED KeypadLib TextLCD RTC-DS1307

Files at this revision

API Documentation at this revision

Comitter:
boki96
Date:
Sun Feb 02 10:22:43 2020 +0000
Commit message:
The area access control system is implemented by entering a numeric password from the keyboard. Depending on the password, the servo motor unlocks the door. It is also possible to change the password itself, as well as display the date and time.

Changed in this revision

KeypadLib.lib Show annotated file Show diff for this revision Revisions of this file
RGB-LED.lib Show annotated file Show diff for this revision Revisions of this file
RTC-DS1307.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeypadLib.lib	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/rlanghbv/code/KeypadLib/#fb28bc08ded4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGB-LED.lib	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/TVZ2019/code/RGB-LED/#8a23399d0af4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC-DS1307.lib	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/TVZ2019/code/RTC-DS1307/#d1de45595c90
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,310 @@
+#include "mbed.h"
+#include "Rtc_Ds1307.h"
+#include "keypad.h"
+#include "TextLCD.h"
+#include "Servo.h"
+#include "rgb.h"
+
+#define duljinaLozinke 4
+
+RGBLed lediceRGB(PA_5, PA_6, PA_7);
+Keypad tipkovnica(PB_4, PB_14, PB_5, PB_13, PA_8, PB_1, PB_10, PB_15);
+TextLCD lcd(PC_10, PC_11, PC_12, PD_2, PC_3, PC_0);
+Rtc_Ds1307 rtc(PB_9, PB_8);
+Servo mojServo(PB_2);
+
+Ticker blicanje;
+Timer ledBlicanje;
+Timer debounce;
+InterruptIn tipkaloIzlaz(PB_3);
+PwmOut piezoZvucnik(PC_7);
+
+void pocetniPrikaz(void);
+void postaviLozinku_pristup(void);
+void led_flip(void);
+void unosLozinkePristup(void);
+void otkljucavanje(void);
+void promjenaLozinkePristup(void);
+void satDatum(void);
+
+int lozinka_pristup[duljinaLozinke];
+int unos_lozinkePristup[duljinaLozinke];
+int lozinkaPromjena[duljinaLozinke];
+
+
+int main() {
+    Rtc_Ds1307::Time_rtc tm = {};
+    tipkovnica.enablePullUp();
+    mojServo.write(0.0);
+    pocetniPrikaz();
+    postaviLozinku_pristup();
+    debounce.start();
+    tipkaloIzlaz.rise(&otkljucavanje);
+    
+    while (1) {
+        char utipkano = tipkovnica.getKey();
+        switch (utipkano) {
+            case 'A':
+                promjenaLozinkePristup();
+                break;
+            case '#':
+                unosLozinkePristup();
+                break;
+            default:
+            {
+                if (rtc.getTime(tm)) {
+                    lcd.locate(3, 0);
+                    lcd.printf("%02d.%02d.%04d.", tm.date, tm.mon, tm.year);
+                    lcd.locate(4, 1);
+                    lcd.printf("%02d:%02d:%02d", tm.hour, tm.min, tm.sec);
+                }
+            }
+        }
+    }
+}
+
+
+void pocetniPrikaz(void) {
+    blicanje.attach(&led_flip, 0.5);
+    lcd.cls();
+    lcd.printf("DULJINA LOZINKE");
+    lcd.locate(0, 1);
+    lcd.printf("    %d ZNAKA    ", duljinaLozinke);
+    wait(2.0);
+    lcd.cls();
+    lcd.printf("* POSTAVLJANJE *");
+    lcd.locate(0, 1);
+    lcd.printf("*   LOZINKE    *");
+    wait(2.0);
+    lcd.cls();
+    blicanje.detach();
+    lediceRGB.prikaz(0.0, 0.0, 0.0);
+    
+}
+
+void led_flip(void) {
+    lediceRGB.prikaz(0.0, 0.0, 1.0);
+    ledBlicanje.start();
+    if (ledBlicanje.read_ms() >= 500) {
+        lediceRGB.prikaz(0.0, 0.0, 0.0);
+        ledBlicanje.reset();
+    }
+}
+    
+void postaviLozinku_pristup(void) {
+    blicanje.attach(&led_flip, 0.2);
+    lcd.printf("POSTAVI LOZINKU");
+    lcd.locate(0, 1);
+    lcd.printf("   ZA PRISTUP   ");
+    wait(1.5);
+    lcd.cls();
+    lcd.printf("POSTAVI LOZINKU");
+    lcd.locate(6, 1);
+    
+    uint8_t i = 0;
+    do {
+        char utipkano = tipkovnica.getKey();
+        if (utipkano != KEY_RELEASED && utipkano >= '0' && utipkano <= '9') {
+            lozinka_pristup[i] = utipkano - 48;
+            lcd.printf("*");
+            wait(0.2);
+            ++i;
+        } else if ((utipkano != KEY_RELEASED) && (utipkano < '0' || utipkano > '9')) {
+            blicanje.detach();
+            lediceRGB.prikaz(1.0, 0.0, 0.0);
+            lcd.cls();
+            lcd.printf(" POGRESAN UNOS! ");
+            piezoZvucnik.period(0.006);
+            piezoZvucnik.write(0.1);
+            wait(1.0);
+            piezoZvucnik.write(0.0);
+            lcd.cls();
+            lediceRGB.prikaz(0.0, 0.0, 0.0);
+            lcd.printf("POSTAVI LOZINKU");
+            lcd.locate(6, 1);
+            i = 0;
+            blicanje.attach(&led_flip, 0.2);
+        }
+    } while (i < duljinaLozinke);
+    
+    lcd.cls();
+    blicanje.detach();
+    lcd.printf("    LOZINKA     ");
+    lcd.locate(0, 1);
+    lcd.printf(" JE POSTAVLJENA ");
+    piezoZvucnik.period(0.001);
+    piezoZvucnik.write(0.5);
+    lediceRGB.prikaz(0.0, 1.0, 0.0);
+    wait(2.0);
+    blicanje.detach();
+    lediceRGB.prikaz(0.0, 0.0, 0.0);
+    piezoZvucnik.write(0.0);
+    lcd.cls();
+}
+
+void unosLozinkePristup(void) {
+    lcd.cls();
+    lcd.printf("UNESITE LOZINKU");
+    blicanje.attach(&led_flip, 0.2);
+    lcd.cls();
+    lcd.printf("  UNOS LOZINKE  ");
+    lcd.locate(6, 1);
+    
+    uint8_t i = 0;
+    do {
+        char utipkano = tipkovnica.getKey();
+        if (utipkano != KEY_RELEASED && utipkano >= '0' && utipkano <= '9') {
+            unos_lozinkePristup[i] = utipkano - 48;
+            lcd.printf("*");
+            wait(0.2);
+            ++i;
+        }
+    } while (i < duljinaLozinke);
+    blicanje.detach();
+    
+    uint8_t brojac = 0;
+    for (uint8_t i = 0; i < duljinaLozinke; ++i) {
+        if (unos_lozinkePristup[i] == lozinka_pristup[i]) 
+            brojac++;
+    }
+            
+    if (brojac == duljinaLozinke) {
+        lediceRGB.prikaz(0.0, 1.0, 0.0);
+        lcd.cls();
+        lcd.printf("    PRISTUP    ");
+        lcd.locate(4, 1);
+        lcd.printf("OMOGUCEN");
+        piezoZvucnik.period(0.001);
+        piezoZvucnik.write(0.5);
+        wait(2.0);
+        lcd.cls();
+        otkljucavanje();
+    } else if (brojac != duljinaLozinke) {
+        lediceRGB.prikaz(1.0, 0.0, 0.0);
+        lcd.cls();
+        lcd.printf("    PRISTUP    ");
+        lcd.locate(3, 1);
+        lcd.printf("ONEMOGUCEN");
+        piezoZvucnik.period(0.004);
+        piezoZvucnik.write(0.1);
+        wait(2.0);
+        lediceRGB.prikaz(0.0, 0.0, 0.0);
+        piezoZvucnik.write(0.0);
+        lcd.cls();
+    }
+}
+
+void promjenaLozinkePristup(void) {
+    lcd.cls();
+    blicanje.attach(&led_flip, 0.2);
+    lcd.printf("PROMJENA LOZINKE");
+    lcd.locate(0, 1);
+    lcd.printf("   ZA PRISTUP   ");
+    lcd.cls();
+    lcd.printf("TRENUTNA LOZINKA");
+    lcd.locate(6, 1);
+    
+    uint8_t i = 0;
+    do {
+        char utipkano = tipkovnica.getKey();
+        if (utipkano != KEY_RELEASED && utipkano >= '0' && utipkano <= '9') {
+            lozinkaPromjena[i] = utipkano - 48;
+            lcd.printf("*");
+            wait(0.2);
+            ++i;
+        }
+    } while (i < duljinaLozinke);
+    blicanje.detach();
+    
+    uint8_t brojac = 0;
+    for (uint8_t i = 0; i < duljinaLozinke; ++i) {
+        if (lozinkaPromjena[i] == lozinka_pristup[i])
+            brojac++;
+    }
+    
+    if (brojac == duljinaLozinke) {
+        lediceRGB.prikaz(0.0, 1.0, 0.0);
+        wait(1.0);
+        lediceRGB.prikaz(0.0, 1.0, 0.0);
+        blicanje.attach(&led_flip, 0.2);
+        lcd.cls();
+        lcd.printf(" NOVA LOZINKA");
+        lcd.locate(6, 1);
+        
+        uint8_t i = 0;
+        do {
+            char utipkano = tipkovnica.getKey();
+            if (utipkano != KEY_RELEASED && utipkano >= '0' && utipkano <= '9') {
+                lozinka_pristup[i] = utipkano - 48;
+                lcd.printf("*");
+                wait(0.2);
+                ++i;
+            }
+        } while (i < duljinaLozinke);
+        blicanje.detach();
+        
+        lcd.cls();
+        lcd.locate(4, 0);
+        lcd.printf("LOZINKA");
+        lcd.locate(0, 1);
+        lcd.printf("JE PROMIJENJENA!");
+        piezoZvucnik.period(0.001);
+        piezoZvucnik.write(0.5);
+        lediceRGB.prikaz(0.0, 1.0, 0.0);
+        wait(2.0);
+        piezoZvucnik.write(0.0);
+        lediceRGB.prikaz(0.0, 0.0, 0.0);
+        lcd.cls();
+    } else if (brojac != duljinaLozinke) {
+        lediceRGB.prikaz(1.0, 0.0, 0.0);
+        lcd.cls();
+        lcd.printf("KRIVA LOZINKA...");
+        lcd.locate(0, 1);
+        lcd.printf("UNESITE PONOVNO!");
+        wait(1.0);
+        lediceRGB.prikaz(0.0, 0.0, 0.0);
+        lcd.cls();
+    }
+}
+
+void otkljucavanje(void) {
+    if (debounce.read_ms() > 200) {
+    piezoZvucnik.period(0.001);
+    piezoZvucnik.write(0.2);
+    wait(0.5);
+    lcd.cls();
+    lediceRGB.prikaz(0.0, 1.0, 0.0);
+    lcd.printf(" OTKLJUCAVANJE! ");
+    lcd.locate(0, 1);
+    lcd.printf("****************");
+    mojServo.write(90.0);
+    wait(1.5);
+    lcd.cls();
+    lcd.printf("****************");
+    lcd.locate(0, 1);
+    lcd.printf("   OTKLJUCANO   ");
+    piezoZvucnik.write(0.0);
+    
+    wait(10.0);
+    
+    lcd.cls();
+    piezoZvucnik.period(0.001);
+    piezoZvucnik.write(0.5);
+    lediceRGB.prikaz(1.0, 0.0, 0.0);
+    lcd.printf(" ZAKLJUCAVANJE! ");
+    lcd.locate(0, 1);
+    lcd.printf("****************");
+    mojServo.write(0.0);
+    wait(1.5);
+    lcd.cls();
+    lcd.printf("****************");
+    lcd.locate(0, 1);
+    lcd.printf("   ZAKLJUCANO   ");
+    wait(1.5);
+    lediceRGB.prikaz(0.0, 0.0, 0.0);
+    piezoZvucnik.write(0.0);
+    lcd.cls();
+    debounce.reset();
+    lcd.cls();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Feb 02 10:22:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file