This program demonstrates how to use a MicroNFCBoard as a peripheral from any mbed target and blink the board's LEDs.
Dependencies: MicroNFCBoardAPI mbed
Fork of MicroNFCBoardAPI_Blink by
Diff: main.cpp
- Revision:
- 0:e6bbb5a92267
- Child:
- 1:5b804c0c8aa8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 24 13:01:12 2015 +0000 @@ -0,0 +1,80 @@ +/* +MicroNFCBoard mbed API + +Copyright (c) 2014-2015 AppNearMe Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +#include "mbed.h" +#include "micronfcboard.h" + +MicroNFCBoard nfc(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, D9); + +int main() { + nfc.init(); + bool b = true; + for(int i = 0; i < 10; i++) + { + nfc.setLeds(b, !b); + wait_ms(200); + b = !b; + } + + //Start polling + while(true) + { + printf("Poll\r\n"); + nfc.startPolling(); + + while( nfc.polling() ); + + if( nfc.type2() ) + { + printf("Connected to type 2 tag\r\n"); + } + else if( nfc.p2p() ) + { + printf("Connected in P2P mode\r\n"); + } + + bool ndefRead = false; + bool ndefReadingStarted = false; + while( nfc.connected() ) + { + if( !ndefReadingStarted && nfc.ndefReadable() ) + { + printf("Reading tag\r\n"); + ndefReadingStarted = true; + nfc.ndefRead(); + } + if( !ndefRead && nfc.ndefPresent() ) + { + printf("Got message\r\n"); + char buf[512]; + if( nfc.readNdefUri(buf, sizeof(buf)) ) + { + printf("Got URI: %s\r\n", buf); + } + if( nfc.readNdefText(buf, sizeof(buf)) ) + { + printf("Got Text: %s\r\n", buf); + } + ndefRead = true; + } + } + + printf("Disconnected\r\n"); + } +} + \ No newline at end of file