Kapii_Ornegi

Dependencies:   mbed Servo MFRC522 TextLCD keypad

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "Keypad.h"
00004 #include <string>
00005 #include "MFRC522.h"
00006 
00007 #define SIFRE "**123A"  // sifreyi kendinize göre değistirebilirsiniz
00008 #define uzunluk 6       // girdiğiniz sifre ne kadar uzunsa buraya sayısını giriniz
00009 
00010 string sifre= "";
00011 uint8_t hata=4;
00012 
00013 char key_table[] = {
00014     '1', '2', '3', 'A',
00015     '4', '5', '6', 'B',
00016     '7', '8', '9', 'C',
00017     '*', '0', '#', 'D'
00018 };
00019 
00020 Keypad key(PA_12,PA_11,PB_12,PB_2,PB_1,PB_15,PB_14,PB_13);
00021 TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); // rs, e, d4-d7..
00022 
00023 DigitalOut buzzer(D7);
00024 Servo servo1(PA_15);
00025 
00026 MFRC522 RfChip(PA_7, PA_6, PA_5, PB_6, PC_7);/**/
00027 
00028 
00029 void hataliGiris()
00030 {
00031     lcd.cls();
00032     lcd.printf("Hatali Giris..");
00033     for(uint8_t a = 10; a > 1; a--) {
00034         buzzer=1;
00035         wait_ms(50);
00036         buzzer=0;
00037         wait_ms(10);
00038     }
00039     buzzer=0;
00040     hata--;
00041     printf("Hatali Giris..");
00042     wait(3);
00043     lcd.cls();
00044     sifre = "";
00045     if(hata == 1) {
00046         hata = 4;
00047         lcd.printf("   saniye \n bekleyiniz..");
00048         for(uint8_t sure = 60; sure > 0; sure--) {
00049             lcd.locate(0,0);
00050             lcd.printf("%d ",sure);
00051             wait(1);
00052         }
00053     }
00054 }
00055 
00056 int main()
00057 {
00058     uint32_t key_num;
00059     RfChip.PCD_Init();/**/
00060 
00061 Onur:
00062 
00063     lcd.cls();
00064     lcd.printf("Sifre : ");
00065     printf("Sifre : ");
00066 
00067     while(true) {
00068         while ((key_num = key.read()) != 0) { // keypada her basıldığında
00069             
00070             buzzer=1;
00071             wait_ms(50);
00072             buzzer=0;
00073 
00074             lcd.printf("*");
00075             printf("%c", *(key_table + key_num-1));
00076 
00077             sifre += *(key_table + key_num-1); // keypad deki değerler sifre adlı değişkende toplanıyor
00078 
00079             if(uzunluk == sifre.length()) {
00080 
00081 
00082                 if(sifre == SIFRE) {  // eger ki sifremiz dogruysa
00083                     lcd.cls();
00084                     lcd.printf("Giris Basarili..");
00085                     printf("Giris Basarili...");
00086                     wait(3);
00087                     lcd.cls();
00088                     sifre = "";
00089                     hata=4;
00090                     goto Onur;
00091                 } else {    // eger sifre hataliysa
00092                     hataliGiris();
00093                     goto Onur;
00094                 }
00095             }
00096 
00097         }
00098         wait(0.2);
00099         ///////////////////////  /*
00100         if ( ! RfChip.PICC_IsNewCardPresent()) {
00101             wait_ms(100);
00102             continue;
00103         }
00104 
00105         if ( ! RfChip.PICC_ReadCardSerial()) {
00106             wait_ms(100);
00107             continue;
00108         }
00109 
00110 // kard ID si yazdırılıyor
00111         printf("Kart ID: ");
00112         for (uint8_t i = 0; i < RfChip.uid.size; i++) {
00113             printf(" %X", RfChip.uid.uidByte[i]);
00114         }
00115         printf("\n");
00116 
00117 // kendinize göre dğeiştirmeniz gerekiyor
00118         if(RfChip.uid.uidByte[0]==0x53 && RfChip.uid.uidByte[1]==0x25 && RfChip.uid.uidByte[2]==0xB6 && RfChip.uid.uidByte[3]== 0x0) {
00119             lcd.cls();
00120             lcd.printf("Giris Basarili..");
00121             printf("Giris Basarili...\n");
00122             wait(3);
00123             lcd.cls();
00124             sifre = "";
00125             hata=4;
00126             goto Onur;
00127         }
00128 
00129         else {  // RFID da okunan kart yanlis ise
00130             hataliGiris();
00131             goto Onur;
00132         }
00133     
00134     } // while(true) {
00135     return 0;
00136 } // int main()