Test example

Dependencies:   mbed

Fork of readMifare by Interactive Device Design

Revision:
2:96f420fa4a6e
Parent:
1:fb72a2f7cab5
Child:
3:08251c301e26
--- a/main.cpp	Fri Sep 19 05:09:50 2014 +0000
+++ b/main.cpp	Mon Nov 03 05:48:29 2014 +0000
@@ -48,6 +48,7 @@
 
 DigitalOut red(LED_RED);
 DigitalOut green(LED_GREEN);
+DigitalOut blue(LED_BLUE);
 
 Serial pc(USBTX, USBRX);
 Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
@@ -56,8 +57,8 @@
 
 int main() {
   pc.printf("Hello!\n");  
-  // By default, red
-  green = 1; red = 0;
+  // By default, no color
+  green = 1; red = 1, blue = 1;
 
   nfc.begin();
 
@@ -82,8 +83,8 @@
 
 
 void loop(void) {
-  // Turn back to red  
-  green = 1; red = 0;
+  // Turn back to no color 
+  green = 1; red = 1, blue = 1;
 
   uint8_t success;
   uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
@@ -96,7 +97,7 @@
   
   if (success) {
     // Turn off to indicate Card swipe
-    green = 1; red = 1;
+    green = 1; red = 1, blue = 1;
     // Display some basic information about the card
     pc.printf("\n\nFound an ISO14443A card\n");
     pc.printf("  UID Length: %d bytes", uidLength);
@@ -121,8 +122,22 @@
       
       if (success)
       {
-        // Turn green to indicate success
-        green = 0; red = 1;
+        // Turn colors to indicate which tag
+        //green = 0; red = 1;
+        uint8_t tag_1 = 250;
+        uint8_t tag_2 = 186;
+        uint8_t tag_3 = 106;
+        uint8_t tag_4 = 10;
+        if (uid[0] == tag_1)
+          green = 0;
+        else if (uid[0] == tag_2)
+          red = 0;
+        else if (uid[0] == tag_3) {
+          green = 0, red = 0;
+        } else if (uid[0] == tag_4) {
+          red = 0, blue = 0;
+        }
+        
         pc.printf("Sector 1 (Blocks 4..7) has been authenticated\n");
         uint8_t data[16];
         
@@ -149,7 +164,7 @@
         ************************************************************************/
         
         // Try to read the contents of block 4
-        success = nfc.mifareclassic_ReadDataBlock(4, data);
+        /*success = nfc.mifareclassic_ReadDataBlock(4, data);
         
         if (success)
         {
@@ -164,7 +179,7 @@
         else
         {
           pc.printf("Ooops ... unable to read the requested block.  Try another key?\n");
-        }
+        }*/
       }
       else
       {