isolation of primary expression for nfc reader

hello
i would like to find the primary expression who's define a single nfc tag to assign function to it and another function to another tag in this programme thanks, here is the code:

//This example reads all MIFARE memory block from 0x00 to 0x63.
//It is tested with a new MIFARE 1K cards. Uses default keys for authenication.
//Contributed by Seeed Technology Inc (www.seeedstudio.com)

#include <PN532.h>
#include <SPI.h>

/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define PN532_CS 10

PN532 nfc(PN532_CS);

#define  NFC_DEMO_DEBUG 1

void setup(void) {
#ifdef NFC_DEMO_DEBUG
  Serial.begin(9600);
  Serial.println("Hello!");
#endif
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
#ifdef NFC_DEMO_DEBUG
    Serial.print("Didn't find PN53x board");
#endif
    while (1); // halt
  }
#ifdef NFC_DEMO_DEBUG
  // Got ok data, print it out!
  Serial.print("Found chip PN5");
  Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. ");
  Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.');
  Serial.println((versiondata >> 8) & 0xFF, DEC);
  Serial.print("Supports ");
  Serial.println(versiondata & 0xFF, HEX);
#endif
  // configure board to read RFID tags and cards
  nfc.SAMConfig();
}

void loop(void) {
  uint32_t id;
  // look for MiFare type cards
  id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

  if (id != 0)
  {
#ifdef NFC_DEMO_DEBUG
    Serial.print("Read card #");
    Serial.println(id);
    Serial.println();
#endif
    uint8_t keys[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // default key of a fresh card
    for (uint8_t blockn = 0; blockn < 64; blockn++)
    {
      if (nfc.authenticateBlock(1, id , blockn, KEY_A, keys)) //authenticate block blockn
      {
        //if authentication successful
        uint8_t block[16];
        //read memory block blockn
        if (nfc.readMemoryBlock(1, blockn, block))
        {
#ifdef NFC_DEMO_DEBUG
          //if read operation is successful
          for (uint8_t i = 0; i < 16; i++)
          {
            //print memory block
            Serial.print(block[i], HEX);
            if (block[i] <= 0xF) //Data arrangement / beautify
            {
              Serial.print("  ");
            }
            else
            {
              Serial.print(" ");
            }
          }

          Serial.print("| Block ");
          if (blockn <= 9) //Data arrangement / beautify
          {
            Serial.print(" ");
          }
          Serial.print(blockn, DEC);
          Serial.print(" | ");

          if (blockn == 0)
          {
            Serial.println("Manufacturer Block");
          }
          else
          {
            if (((blockn + 1) % 4) == 0)
            {
              Serial.println("Sector Trailer");
            }
            else
            {
              Serial.println("Data Block");
            }
          }
#endif
        }

there is a smiley and italic font in your code...

see rules for posting here...

sorry about that, it was in the code i didnt put it there

that's your post, don't blame someone else... you are responsible for what you write here.

Read the rules for posting

i dont blame anyone, i just said there was no italic or smiley in the initial code, the forum interpreted the code that i past but sorry for that

i modified the code about the smiley hope it will help and thanks for your accuracy:
Serial.println((versiondata>> 8 ) & 0xFF, DEC);

https://forum.arduino.cc/index.php?topic=149014.0

doesnt help

  • Go read the rules for posting
  • fix your posts
  • then clarify exactly what it is you are trying to do that the code you posted does not do

i did, i try to assign command to a nfc tag when this one is readed i can't be more clear

Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

I can't be clearer either.

Bye.

ok its done

so the example you posted does this:

This example reads all MIFARE memory block from 0x00 to 0x63

how does this relate to what you want to do?

if you are looking at recognizing a specific NFC tag, then start from a code reading the UID and then compare the UID with a list of known UIDs and decide what to do

Also here

i want to specify an id that i have rade before and assign an if to it, and another if to another tag, is it possible?

You could search a list of IDs for an ID just read, and if found perform some action

if UID on less than 32 bits you do if/else

if (UID_I_READ == UID_1) {
  function1();
} else
if (UID_I_READ == UID_2) {
  function2();
} else
if (UID_I_READ == UID_3) {
  function3();
} else {
  // unknown UID
}

or with a switch/case

  switch (UID_I_READ) {
    case UID_1:
      function1();
      break;
    case UID_2:
      function2();
      break;
    case UID_3:
      function3();
      break;
    default:
      break;
  }

if it's more than 32 bits, then use memcmp() in your if

thanks a lot ill try it tonight or tomorow morning but thanks for your time

your code is good but the probleme still, how could i define
UID_I_READ i dont recognise the term who define the reading action to define it, i m wondering if its in the initial code or if its in a library[/code][/code]

that was just a variable name to say "this variable contains the UID I (JUST) READ" -> look at examples on how to read the UID of a Mifare Tag