From 99cc4163da3315c752efb094f34a9d78c8e7cf27 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 17 Nov 2016 22:48:57 +0100 Subject: [PATCH] remove funktion --- .../T11_RFID_Tutorial_Sketch.ino | 72 +++++++++++++++++-- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/T11_RFID_Tutorial_Sketch/T11_RFID_Tutorial_Sketch.ino b/T11_RFID_Tutorial_Sketch/T11_RFID_Tutorial_Sketch.ino index a44cb91..76210f8 100644 --- a/T11_RFID_Tutorial_Sketch/T11_RFID_Tutorial_Sketch.ino +++ b/T11_RFID_Tutorial_Sketch/T11_RFID_Tutorial_Sketch.ino @@ -36,7 +36,9 @@ boolean outputOn = false; int displayLogIndex = -1; int displayLogIndexLast = -1; - +int displayCardsIndex = -1; +int displayCardsIndexLast = -1; +boolean cardsshow=false; void setup() { pinMode(10, OUTPUT); // LCD backlight @@ -174,9 +176,18 @@ void handleCards(long currentMillis) { if(unlocked) { if(save_client_uid(&(mfrc522.uid))) { lcd.clear(); - lcd.print("Karte wurde"); + lcd.print("Hinzugefuegt"); lcd.setCursor(0, 1); - lcd.print("hinzugefuegt"); + lcd.print(""); + lcd_print_uid(&(mfrc522.uid)); + + delay(500); + while(!mfrc522.PICC_IsNewCardPresent() && !mfrc522.PICC_ReadCardSerial()){ + delay(50); + } + lcd.setCursor(0, 0); + lcd.print(" "); + delay(200); } else { lcd.clear(); @@ -203,11 +214,11 @@ void loop() { handleCards(currentMillis); - if(readButtons() == 1) { + if(readButtons() == 1 && !cardsshow) { //select button shows log, if not showing cards atm displayLogIndex++; displayLogIndex %= 10; lastActionMillis = currentMillis; - delay(500); + delay(200); } // log display function @@ -224,12 +235,59 @@ void loop() { displayLogIndexLast = displayLogIndex; } - + + + if(readButtons() == 3) { //down + displayCardsIndex++; + displayCardsIndex %= EEP_CLIENT_MAX; + lastActionMillis = currentMillis; + cardsshow=true; + delay(200); + } + if(readButtons() == 4) { //up + displayCardsIndex--; + if (displayCardsIndex<0){ + displayCardsIndex=EEP_CLIENT_MAX-1; + } + displayCardsIndex %= EEP_CLIENT_MAX; + lastActionMillis = currentMillis; + cardsshow=true; + delay(200); + } + // saved cards display function + if(displayCardsIndex != displayCardsIndexLast) { + if(displayCardsIndex >= 0) { + lcd_backlight(true); + lcd.clear(); + lcd.print("SLOT "); + lcd.print(displayCardsIndex); + if (displayCardsIndex==0){ + lcd.print(" Master"); + } + lcd.setCursor(0, 1); + MFRC522::Uid uid = get_uid(displayCardsIndex, EEP_ADDR_START); + lcd_print_uid(&uid); + } + + displayCardsIndexLast = displayCardsIndex; + } + //card removal + if(readButtons() == 1 && cardsshow && unlocked) { //cards are shown, is unlocked an select pressed + lastActionMillis = currentMillis; + lcd.clear(); + lcd.print("Karte"); + lcd.setCursor(0, 1); + lcd.print("entfernt"); + delete_uid(displayCardsIndex, EEP_ADDR_START); + delay(1000); + } // timeout handling for returning to locked state - if(currentMillis - lastActionMillis > 11000) { + if(currentMillis - lastActionMillis > 30000) { unlocked = false; displayLogIndex = -1; + displayCardsIndex = -1; + cardsshow=false; lcd_backlight(false); if(cardWasPresent) {