PN532 NFC module, RFID tag reading error

Hello!
I am new to this forum and just started a new project for my school contest.
And... there has been a programming-related problem that I couldn't figure it out.

I have purchased Arduino Uno and Adafruit PN532 NFC Module for my project.
Am sort of trying to create program which reads RFID tags, its UID and so on.

During research for the wiring, I found an exmaple code from Adafruit which reads tag info from the module and prints it by Serial monitor.
(It is using I2C connection.)

It worked perfectly, so I used it. But later, I wanted to add more practical functions.

For example, if the tag was acting like an ID card, which students or workers use in the entrance of the building,
and automatically logs the whole thing with Time-stamp and saves it into .txt or .csv file, etc.
So I searched what do I have to download(or edit), and found a program named CoolTerm,
which records the Serial Monitor output into a file. It worked, so I kept going on.

In order to sort out the tag which is read once or twice, I thought what if the tag has a integer value which is set to 0 by default.
When the tag is read once, the value adds 1, resulting the value to be 1. When the same tag is read again, it subtracts 1, resulting the value to be 0.
I thought it was an OK idea. So I programmed it on my own. It didn't have any compile error.
When I uploaded it and simulated the system as I planned, it had a problem.

The value is set to 0 permanently(or the value doesn't add up to 1.).
I am attaching source file, and a serial monitor result image.

How should I fix this error, or improve the code? It seems to be very simple yet I couldn't figure it out.
Any suggestions or solutions regarding this code would be very appreciated.

Regards,

Reggie

iso14443a_uid_edited.ino (2.26 KB)

iso14443a_uid.ino (3.19 KB)

#define VAL (0)

This does not define a variable but a preprocessor macro. This results in that every occurrence of the string "VAL" in your source code is replaced by the string "(0)" before handing it over to the compiler.

VAL==VAL+1;

this looks like the following after macro expansion:

(0) == (0) + 1;

The "==" operator compares the left and the right side expression, so this compares 0 to 1 which is always false. Nothing else will happen.

I guess you should read a bit about C/C++ programming before you try to edit existing programs.

By the way, if you're syntax would have been correct, the program would nothing meaningful. It just says hello or goodbye alternatingly regardless of which card is presented.

Thanks for your reply!

I realized my mistake a few hours later, so I edited the source a bit.
As you said, regardless what card represented to the sensor, it just prints "hello" and "goodbye".

I think using array is one method for solving this problem.

But, as you said, I am a newbie and don't know much C/C++.

Currently, I am reading a C book, and some forums regarding the Arduino programming.

Any help would be appreciated. Thanks