Kapii_Ornegi
Dependencies: mbed Servo MFRC522 TextLCD keypad
Diff: main.cpp
- Revision:
- 0:eb13172d8708
- Child:
- 1:ce3de3f1306d
diff -r 000000000000 -r eb13172d8708 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Dec 15 07:31:34 2019 +0000 @@ -0,0 +1,155 @@ +#include "mbed.h" +#include "TextLCD.h" +#include "Keypad.h" +#include <string> +#include "Servo.h" + +#include "MFRC522.h"/**/ + +#define SIFRE "**123A" +#define uzunluk 6 + +string sifre= ""; +uint8_t hata=4; + +char key_table[] = { + '1', '2', '3', 'A', + '4', '5', '6', 'B', + '7', '8', '9', 'C', + '*', '0', '#', 'D' +}; + +Keypad key(PA_12,PA_11,PB_12,PB_2,PB_1,PB_15,PB_14,PB_13); +TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); // rs, e, d4-d7.. + +DigitalOut buzzer(D7); +Servo servo1(PA_15); + +MFRC522 RfChip(PA_7, PA_6, PA_5, PB_6, PC_7);/**/ + +int main() +{ + uint32_t key_num; + RfChip.PCD_Init();/**/ + +Onur: + + lcd.cls(); + servo1.SetPosition(20); + lcd.printf("Sifre : "); + printf("Sifre : "); + + while(true) { + while ((key_num = key.read()) != 0) { + + buzzer=1; + wait_ms(50); + buzzer=0; + + lcd.printf("*"); + printf("%c", *(key_table + key_num-1)); + + sifre += *(key_table + key_num-1); + + if(uzunluk == sifre.length()) { + + if(sifre == SIFRE) { + lcd.cls(); + lcd.printf("Giris Basarili.."); + printf("Giris Basarili..."); + servo1.SetPosition(150); + wait(3); + lcd.cls(); + sifre = ""; + hata=4; + goto Onur; + } else { + lcd.cls(); + lcd.printf("Hatali Giris.."); + for(uint8_t a = 10; a > 1; a--) { + buzzer=1; + wait_ms(50); + buzzer=0; + wait_ms(10); + } + buzzer=0; + hata--; + printf("Hatali Giris.."); + servo1.SetPosition(20); + wait(3); + lcd.cls(); + sifre = ""; + if(hata == 1) { + hata = 4; + lcd.printf(" saniye \n bekleyiniz.."); + for(uint8_t sure = 60; sure > 0; sure--) { + lcd.locate(0,0); + lcd.printf("%d ",sure); + wait(1); + } + } + goto Onur; + } + } + + } + wait(0.2); + /////////////////////// /* + if ( ! RfChip.PICC_IsNewCardPresent()) { + wait_ms(100); + continue; + } + + if ( ! RfChip.PICC_ReadCardSerial()) { + wait_ms(100); + continue; + } + + printf("Kart ID: "); + for (uint8_t i = 0; i < RfChip.uid.size; i++) { + printf(" %X", RfChip.uid.uidByte[i]); + } + printf("\n"); + + if(RfChip.uid.uidByte[0]==0x53 && RfChip.uid.uidByte[1]==0x25 && RfChip.uid.uidByte[2]==0xB6 && RfChip.uid.uidByte[3]== 0x0) { + lcd.cls(); + lcd.printf("Giris Basarili.."); + printf("Giris Basarili...\n"); + servo1.SetPosition(150); + wait(3); + lcd.cls(); + sifre = ""; + hata=4; + goto Onur; + } + + else { + lcd.cls(); + lcd.printf("Hatali Giris.."); + for(uint8_t a = 10; a > 1; a--) { + buzzer=1; + wait_ms(50); + buzzer=0; + wait_ms(10); + } + buzzer=0; + hata--; + printf("Hatali Giris..\n"); + servo1.SetPosition(20); + wait(3); + lcd.cls(); + sifre = ""; + if(hata == 1) { + hata = 4; + lcd.printf(" saniye \n bekleyiniz.."); + for(uint8_t sure = 60; sure > 0; sure--) { + lcd.locate(0,0); + lcd.printf("%d ",sure); + wait(1); + } + } + goto Onur; + } + return 0; + } +} \ No newline at end of file