Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.28 KB | None | 0 0
  1. /*
  2.  *  BIBLIOTEKI
  3.  */
  4. #include <SPI.h>                  //Magistrala SPI
  5. #include <MFRC522.h>              //CzytnikRFID
  6. #include <LiquidCrystal_I2C.h>    //LCD
  7. #include <Wire.h>                 //Magistrala I2C
  8.  
  9. /*
  10.  * KONFIGURACJA CZYTNIKA RFID
  11.  */
  12. #define SS_PIN 10                     //SS Pin
  13. #define RST_PIN 9                     //Reset Pin
  14. MFRC522 mfrc522(SS_PIN, RST_PIN);     //Delkaracja pinów dla RFID
  15.  
  16.  
  17. /*
  18.  * KONFIGURACJA WYŚWIETLACZA LCD
  19.  */
  20. LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7,3, POSITIVE); //Deklaracja pinów wyświetlacza dla magistrali I2C
  21.  
  22.  
  23. /*
  24.  * ZMIENNE POWIĄZANE Z SYSTEMEM ALARMOWYM
  25.  */
  26. int TRYB = 0;         //Deklaracja zmiennej i ustawienie trybu zero - alarm rozbrojony.
  27. int ALARM_CZAS = 9;   //Czas do rozbrojenia alarmu
  28. String NAGLOWEK = "HackMe Security";
  29.  
  30. /*
  31.  * PRZYPISANIE NUMERU DLA PINÓW
  32.  */
  33. int CZUJNIK = 12;
  34. int BUZZER = 3;
  35.  
  36.  
  37.  
  38. /*
  39.  * FUNKCJA SETUP()
  40.  */
  41. void setup()
  42. {
  43.   Serial.begin(9600);             //Inicjalizacja serial monitora
  44.   SPI.begin();                    //Uruchomienie magistrali SPI
  45.   mfrc522.PCD_Init();             //Uruchomienie czytnika RFID
  46.   lcd.begin(16,2);                //Konfiguracja wyswietlacza (16x02)
  47.  
  48.   pinMode(BUZZER,OUTPUT);         //Konfigracja pinu wyjściowego dla buzzera
  49.   pinMode(CZUJNIK,INPUT);         //Konfiguracja pinu wejściowego dla buzzera
  50.  
  51.   lcd.home();                     //Ustawienie pozycji kursora na wyswietlaczu na pozycje startowa
  52.   lcd.clear();                    //Wyczyszczenie wyswietlacza
  53. }
  54.  
  55.  
  56. /*
  57.  * Funkcja LOOP()
  58.  */
  59. void loop()
  60. {
  61.   if(TRYB==0) function_tryb_0();
  62.   else if(TRYB==1) function_tryb_1();
  63.   else if(TRYB==2) function_tryb_2();
  64.   else if(TRYB==3) function_tryb_3();
  65. }
  66.  
  67.  
  68.  
  69. /*
  70.  * TRYB: 0
  71.  */
  72. void function_tryb_0(){
  73. lcd.clear();
  74. lcd.setCursor(0,0);
  75. lcd.print(NAGLOWEK);
  76. lcd.setCursor(0,1);
  77. lcd.print("Rozbrojony...");
  78. delay(2000);
  79.  
  80.   if ( ! mfrc522.PICC_IsNewCardPresent())
  81.   {
  82.     return;
  83.   }
  84.   if ( ! mfrc522.PICC_ReadCardSerial())
  85.   {
  86.     return;
  87.   }
  88.   String content= "";
  89.   byte letter;
  90.   for (byte i = 0; i < mfrc522.uid.size; i++)
  91.   {
  92.    
  93.      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  94.      content.concat(String(mfrc522.uid.uidByte[i], HEX));
  95.   }
  96.   content.toUpperCase();
  97.   if (content.substring(1) == "77 B1 3C 5B")
  98.   {
  99.  
  100.     lcd.setCursor(0,1);
  101.     lcd.print("Prosze wyjsc: ");
  102.     lcd.setCursor(14,1);
  103.     lcd.print("10");
  104.     analogWrite(BUZZER,230);
  105.     delay(300);
  106.     digitalWrite(BUZZER,LOW);
  107.     delay(700);
  108.     lcd.setCursor(14,1);
  109.     lcd.print("  ");
  110.     lcd.setCursor(14,1);
  111.     lcd.print("9");
  112.     analogWrite(BUZZER,230);
  113.     delay(300);
  114.     digitalWrite(BUZZER,LOW);
  115.     delay(700);
  116.     lcd.setCursor(14,1);
  117.     lcd.print("8");
  118.     analogWrite(BUZZER,230);
  119.     delay(300);
  120.     digitalWrite(BUZZER,LOW);
  121.     delay(700);
  122.     lcd.setCursor(14,1);
  123.     lcd.print("7");
  124.     analogWrite(BUZZER,230);
  125.     delay(300);
  126.     digitalWrite(BUZZER,LOW);
  127.     delay(700);
  128.     lcd.setCursor(14,1);
  129.     lcd.print("6");
  130.     analogWrite(BUZZER,230);
  131.     delay(300);
  132.     digitalWrite(BUZZER,LOW);
  133.     delay(700);
  134.     lcd.setCursor(14,1);
  135.     lcd.print("5");
  136.     analogWrite(BUZZER,230);
  137.     delay(300);
  138.     digitalWrite(BUZZER,LOW);
  139.     delay(700);
  140.     lcd.setCursor(14,1);
  141.     lcd.print("4");
  142.    analogWrite(BUZZER,230);
  143.     delay(300);
  144.     digitalWrite(BUZZER,LOW);
  145.     delay(700);
  146.      lcd.setCursor(14,1);
  147.     lcd.print("3");
  148.     analogWrite(BUZZER,230);
  149.     delay(300);
  150.     digitalWrite(BUZZER,LOW);
  151.     delay(700);
  152.      lcd.setCursor(14,1);
  153.     lcd.print("2");
  154.     analogWrite(BUZZER,230);
  155.     delay(300);
  156.     digitalWrite(BUZZER,LOW);
  157.     delay(700);
  158.      lcd.setCursor(14,1);
  159.     lcd.print("1");
  160.     analogWrite(BUZZER,230);
  161.     delay(300);
  162.     digitalWrite(BUZZER,LOW);
  163.     delay(700);
  164.     lcd.setCursor(0,1);
  165.     lcd.print("                             ");
  166.     analogWrite(BUZZER,230);
  167.     delay(300);
  168.     digitalWrite(BUZZER,LOW);
  169.     delay(700);
  170.      lcd.setCursor(0,1);
  171.     lcd.print("Sys. uzbrojony!");
  172.     analogWrite(BUZZER,240);
  173.     delay(1000);
  174.     digitalWrite(BUZZER,LOW);
  175.     TRYB=1;
  176.    
  177.   }
  178.  
  179.  
  180.    
  181. }
  182.  
  183.  
  184.  
  185.  
  186.  
  187. void function_tryb_1(){
  188.  /*  Tryb 1 sprawdza stan czujnika. Jesli jest duzy to wywołuje tryb 2*/
  189.  
  190. if(digitalRead(CZUJNIK)==HIGH){
  191.   TRYB=2;
  192.   lcd.setCursor(0,1);
  193.     lcd.print("                ");
  194.     ALARM_CZAS = 10;
  195.     TRYB=2;
  196. }
  197.  
  198. }
  199.  
  200. void function_tryb_2(){
  201.  
  202.  
  203.   if (mfrc522.PICC_IsNewCardPresent())
  204.   {
  205.  
  206.   if (mfrc522.PICC_ReadCardSerial())
  207.   {
  208.  
  209.   String content= "";
  210.   byte letter;
  211.   for (byte i = 0; i < mfrc522.uid.size; i++)
  212.   {
  213.    
  214.      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  215.      content.concat(String(mfrc522.uid.uidByte[i], HEX));
  216.   }
  217.   content.toUpperCase();
  218.   if (content.substring(1) == "77 B1 3C 5B")
  219.   {
  220.     TRYB=0;
  221.   }
  222.  
  223.   }
  224.  
  225.   }
  226.   else{
  227.  
  228.     lcd.setCursor(0,1);
  229.     lcd.print("                     ");
  230.     lcd.setCursor(0,1);
  231.     lcd.print("Alarm za...");
  232.     lcd.setCursor(12,1);
  233.     lcd.print(ALARM_CZAS);
  234.     ALARM_CZAS=ALARM_CZAS-1;
  235.     analogWrite(BUZZER,230);
  236.     delay(200);
  237.     digitalWrite(BUZZER,LOW);
  238.     delay(200);
  239.      analogWrite(BUZZER,230);
  240.     delay(200);
  241.     digitalWrite(BUZZER,LOW);
  242.     delay(400);
  243.     if(ALARM_CZAS==0)
  244.     {
  245.        lcd.setCursor(0,1);
  246.     lcd.print("                     ");
  247.     lcd.setCursor(0,1);
  248.     lcd.print("ALARM!!!!!!");
  249.     TRYB=3;
  250.     }
  251.    
  252. }
  253.  
  254. }
  255.  
  256. void function_tryb_3(){
  257.    if (mfrc522.PICC_IsNewCardPresent())
  258.   {
  259.  
  260.   if (mfrc522.PICC_ReadCardSerial())
  261.   {
  262.  
  263.   String content= "";
  264.   byte letter;
  265.   for (byte i = 0; i < mfrc522.uid.size; i++)
  266.   {
  267.    
  268.      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  269.      content.concat(String(mfrc522.uid.uidByte[i], HEX));
  270.   }
  271.   content.toUpperCase();
  272.   if (content.substring(1) == "77 B1 3C 5B")
  273.   {
  274.     TRYB=0;
  275.   }
  276.  
  277.   }
  278.  
  279.   }
  280.   else{
  281.     int i =0;
  282.      
  283.         for(i = 1; i <= 10; i++)
  284.         {
  285.    
  286.             analogWrite(BUZZER, 200);
  287.             delay(100);
  288.             analogWrite(BUZZER, 100);
  289.             delay(100);
  290.      
  291.             analogWrite(BUZZER, 0);
  292.         }
  293.   }
  294. }
  295.  
  296. void wyczysc_ekran(){
  297.    lcd.setCursor(0,1);
  298.    lcd.print("                   ");
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement