// this function ready the Display Buttons (analog pin) // the values from analogRead are due tu a Voltage Divider inline byte readButtons() { int c = analogRead(BTN_PIN); if(c > 1000) { return 0; } else if(c < 650 && c > 630) { return 1; // select } else if(c < 420 && c > 370) { return 2; // left } else if(c < 280 && c > 200) { return 3; // down } return 4; // up } // switch the output Relaid on/off void set_output(boolean on) { if(on) { digitalWrite(A4, LOW); } else { digitalWrite(A4, HIGH); } outputOn = on; } // switch the LDC Backlight on/off void lcd_backlight(boolean on) { if(on) { lcdbacklight=true; digitalWrite(LCD_BACKLIGHT, HIGH); } else { lcdbacklight=false; digitalWrite(LCD_BACKLIGHT, LOW); } } bool get_lcd_backlight(){ return lcdbacklight; } // print a Mifare UID at current LDC position void lcd_print_uid(MFRC522::Uid *uid) { for (byte i=0; i < uid->size; i++) { lcd.print(uid->uidByte[i] < 0x10 ? " 0" : " "); lcd.print(uid->uidByte[i], HEX); } } // gives index of stored card uid if any, otherwise -1 int check_uid(MFRC522::Uid *uid) { MFRC522::Uid uid2; for(byte i=0; i < 1+EEP_CLIENT_MAX; i++) { uid2 = get_uid(i, EEP_ADDR_START); if(compare_uids(uid, &uid2)) { return i; } } return -1; } boolean compare_uids(MFRC522::Uid *uid1, MFRC522::Uid *uid2) { if(uid1->size != uid2->size) { return false; } for(byte j=0;jsize;j++) { if(uid1->uidByte[j] != uid2->uidByte[j]) { return false; } } return true; } // get a uid from EEPROM at given index + start Address MFRC522::Uid get_uid(byte index, int startAddress) { MFRC522::Uid uid; int address = startAddress + index * EEP_ADDR_UID_INCREMENT; uid.size = 0; EEPROM.get(address, uid); return uid; } // delete a UID at the given index + start Address void delete_uid(int index, int startAddress) { int address = startAddress + index * EEP_ADDR_UID_INCREMENT; for(byte i=0; i < EEP_ADDR_UID_INCREMENT; i++) { EEPROM.write(address+i, 0); } } // store the master UID at first address of EEPROM void save_master_uid(MFRC522::Uid *uid) { EEPROM.put(EEP_ADDR_START, *uid); } boolean save_client_uid(MFRC522::Uid *uid) { byte index = EEP_CLIENT_MAX; // try to find a free slot in EEPROM for(byte i=0; i 0; i--) { temp.size = 0; EEPROM.get(EEP_ADDR_LOG_START + (i - 1) * EEP_ADDR_UID_INCREMENT, temp); if(temp.size != 0 && temp.size != 255) { EEPROM.put(EEP_ADDR_LOG_START + i * EEP_ADDR_UID_INCREMENT, temp); } } EEPROM.put(EEP_ADDR_LOG_START, *uid); } // a debug function for showing all UID from EEPROM over Serial void dump_uid(byte count, int address) { MFRC522::Uid uid; for(byte i=0; i< count; i++) { uid = get_uid(i, address); Serial.print("slot "); if(i < 10) Serial.print(" "); Serial.print(i); Serial.print(":"); for (byte j=0;j<10;j++) { Serial.print(uid.uidByte[j] < 0x10 ? " 0" : " "); Serial.print(uid.uidByte[j], HEX); } Serial.println(" "); } }