Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- #include <SPI.h>
- #include <MFRC522.h>
- #define RST_PIN 9 // Configurable, see typical pin layout above
- #define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
- #define NR_OF_READERS 1
- byte ssPins[] = {SS_1_PIN};
- MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- unsigned long kod;
- boolean run = false;
- boolean run2 = false;
- long timer = 0; //The timer
- int second = 0;
- int minute = 0;
- int tenth = 0;
- int hour =0;
- int second2 = 0;
- int minute2 = 0;
- int tenth2 = 0;
- int hour2 =0;
- const int rfrele = 3;
- const int gdprele = 4;
- const int buzzer = 5;
- void setup() {
- Serial.begin(9600);
- SPI.begin();
- lcd.begin();
- lcd.backlight();
- pinMode(rfrele,OUTPUT);
- pinMode(gdprele,OUTPUT);
- pinMode(buzzer,OUTPUT);
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
- Serial.print(F("Reader "));
- Serial.print(reader);
- Serial.print(F(": "));
- mfrc522[reader].PCD_DumpVersionToSerial();
- }
- lcd.setCursor(0,0);
- lcd.print("RF 00:00:00");
- lcd.setCursor(0,1);
- lcd.print("GD 00:00:00");
- }
- void tickClock() {
- if((timer - millis()/100) >= 100 || timer == 0) {
- tick();
- tick2();
- timer = millis()/100;
- }
- }
- void loop() {
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
- Serial.print(F("Reader "));
- Serial.print(reader);
- // Show some details of the PICC (that is: the tag/card)
- Serial.print(F(": Card UID:"));
- dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
- Serial.println();
- Serial.print(F("PICC type: "));
- MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
- Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
- // Halt PICC
- mfrc522[reader].PICC_HaltA();
- // Stop encryption on PCD
- mfrc522[reader].PCD_StopCrypto1();
- } //if (mfrc522[reader].PICC_IsNewC
- } //for(uint8_t reader
- if(kod==4294957290){
- digitalWrite(rfrele, HIGH);
- digitalWrite(gdprele, LOW);
- run = false;
- run2 = true;
- }else if(kod==17691){
- digitalWrite(rfrele, LOW);
- digitalWrite(gdprele, HIGH);
- run = true;
- run2 = false;
- }else if(kod==12619){
- digitalWrite(rfrele, HIGH);
- digitalWrite(gdprele, HIGH);
- run = false;
- run2 = false;
- }else if(kod==26377){
- digitalWrite(rfrele, HIGH);
- digitalWrite(gdprele, HIGH);
- second = 0;
- minute = 0;
- tenth = 0;
- hour =0;
- second2 = 0;
- minute2 = 0;
- tenth2 = 0;
- hour2 =0;
- updateLCD();
- updateLCD2();
- run = false;
- run2 = false;
- }
- tickClock(); //Start ticking the clock
- }
- void tick() {
- if(run) {
- updateLCD();
- if(tenth == 9) {
- tenth = 0;
- if(second == 59) {
- second = 0;
- minute++;
- }else {
- second++;
- }
- if(minute == 60) {
- minute = 0;
- hour++;
- }
- } else {
- tenth++;
- }
- }
- }
- void tick2() {
- if(run2) {
- updateLCD2();
- if(tenth2 == 9) {
- tenth2 = 0;
- if(second2 == 59) {
- second2 = 0;
- minute2++;
- }else {
- second2++;
- }
- if(minute2 == 60) {
- minute2 = 0;
- hour2++;
- }
- } else {
- tenth2++;
- }
- }
- }
- void updateLCD() {
- lcd.setCursor(4,0);
- if(hour < 10) { // If hour does not have 2 digits
- lcd.print("0");
- }
- lcd.print(hour, DEC);
- lcd.print(":");
- if(minute < 10) { // If hour does not have 2 digits
- lcd.print("0");
- }
- lcd.print(minute, DEC);
- lcd.print(":");
- if(second < 10) { // If minute does not have 2 digits
- lcd.print("0");
- }
- lcd.print(second, DEC);
- //
- }
- void updateLCD2() {
- lcd.setCursor(4,1);
- if(hour2 < 10) { // If hour does not have 2 digits
- lcd.print("0");
- }
- lcd.print(hour2, DEC);
- lcd.print(":");
- if(minute2 < 10) { // If hour does not have 2 digits
- lcd.print("0");
- }
- lcd.print(minute2, DEC);
- lcd.print(":");
- if(second2 < 10) { // If minute does not have 2 digits
- lcd.print("0");
- }
- lcd.print(second2, DEC);
- }
- void dump_byte_array(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- }
- kod = 10000*buffer[4]+1000*buffer[3]+100*buffer[2]+10*buffer[1]+buffer[0];
- tone(buzzer, 4000, 100);
- Serial.println("Zaznamenany kod karty: ");
- Serial.println(kod);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement