This program demonstrates how to use a MicroNFCBoard as a peripheral to encode and write NFC tags.

Dependencies:   MicroNFCBoardAPI mbed

Fork of MicroNFCBoardAPI_Blink by AppNearMe Official

Files at this revision

API Documentation at this revision

Comitter:
AppNearMe
Date:
Thu May 14 17:31:16 2015 +0000
Parent:
1:5b804c0c8aa8
Commit message:
Tag writer fork

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 14 16:43:09 2015 +0000
+++ b/main.cpp	Thu May 14 17:31:16 2015 +0000
@@ -23,11 +23,49 @@
 
 int main() {
     nfc.init();
-    bool b = true;
-    for(int i = 0; i < 10; i++)
+
+    //Start polling
+    while(true)
     {
-        nfc.setLeds(b, !b);
-        wait_ms(200);
-        b = !b;
+        printf("Poll\r\n");
+        nfc.startPolling(true, false, false);
+
+        while( nfc.polling() );
+
+        if( nfc.type2Tag() )
+        {
+            printf("Connected to type 2 tag\r\n");
+        }
+        else
+        {
+          continue;
+        }
+
+        bool ndefMessageWritten = false;
+        bool ndefWritingStarted = false;
+        while( nfc.connected() )
+        {
+            if( !ndefWritingStarted && nfc.ndefWriteable() )
+            {
+                printf("Writing tag\r\n");
+                nfc.writeNdefUri("http://www.micronfcboard.com");
+                nfc.ndefWrite();
+                ndefWritingStarted = true;
+            }
+            if( ndefWritingStarted && !ndefMessageWritten && !nfc.ndefBusy() )
+            {
+              ndefMessageWritten = true;
+              if( nfc.ndefSuccess() )
+              {
+                printf("Tag write successful\r\n");
+              }
+              else
+              {
+                printf("Tag write failed\r\n");
+              }
+            }
+        }
+
+        printf("Disconnected\r\n");
     }
 }