Millis function and RFID

Hello,

I hope that somebody can help me with my code.

I have connected arduino+rdm6300+lcd display.

When the RFID tag is read, on the LCD screen is displayed the product name that belongs to a particular

RFID tag.

If I put a millis function, I know how the read time of tag can be displayed on the screen.

But I do not know how to achieve that when the first tag is read, LCD display the corresponding name of

the product and the read time of this product with a note Start time. When the second RFID tag is

read, the corresponding name of product is displayed on the LCD screen so as his reading time with a

note Finished time. Difference between Finished time and Start time is calculated and displayed on the

screen.

Then the Finished time of second read product (second read RFID tag) becomes the Start time of the

second read tag. When the third RFID tag is read, the corresponding name of product of third read

RFID tag is displayed on the LCD screen so as his reading time with a note Finished time. Difference

between Finished time and Start time is calculated and displayed on the screen. Then the Finished time

of this product product becomes the Start time of the third read product.

And so on...

My code is:

#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //postavlja LCD I2C adresu
SoftwareSerial RFID(10, 11); // RX and TX

// LED- to GND
// LED+ to pwm



int check_LED = -1; 
int greenLED = 13;
int redLED = 12;

String tag1 = "25255484855685655567051503";
String tag2 = "25255484855685649695553673"; 
String tag3 = "25255484855685650665448693";
String tag4 = "25255484855685654674955683";
String tag5 = "25255484855685352515753553";

void setup()  {
Serial.begin(9600);
//Serial.println("Serial Ready");

RFID.begin(9600);
//Serial.println("RFID Ready");
pinMode(greenLED, OUTPUT); // for status LEDs

Serial.println("Molimo provucite karticu za početak rada");
 
lcd.begin(20,4);
lcd.backlight(); //upaljena pozadina
lcd.setCursor(0,0); // Start at character 5 on line 0
lcd.print ("Molimo provucite karticu za pocetak rada");
delay(200);
lcd.setCursor(0,1);
}

void readTags()
{
int index =0 ;  
int unit;
String msg;



while(RFID.available()>0)
{
unit = RFID.read();

index++;

msg += unit;

lcd.clear();


if(index == 14 && msg == tag1 )  
{
 Serial.println("Product1");
 lcd.print("Product 1");
 digitalWrite(greenLED, HIGH);
 delay(1000);
 digitalWrite(greenLED, LOW);
 delay (1000);
} 
  
 else if (index == 14 && msg == tag2)
 {
 Serial.println("Product2");
 lcd.print("Product2");
 digitalWrite(greenLED, HIGH);
 delay(1000);
 digitalWrite(greenLED, LOW);
 delay (1000);

 } 
 else if (index == 14 && msg == tag3)
 {
 Serial.println("Product3");
 lcd.print("Product3");
 digitalWrite(greenLED, HIGH);
 delay(1000);
 digitalWrite(greenLED, LOW);
 delay (1000);
 } 
 else if (index == 14 && msg == tag4)
 {
 Serial.println("Product4");
 lcd.print("Product 4");
 digitalWrite(greenLED, HIGH);
 delay(1000);
 digitalWrite(greenLED, LOW);
 delay (1000);
 } 
 else if (index == 14 && msg == tag5)
 {
 Serial.println("Product5");
 lcd.print("Product 5");
 digitalWrite(greenLED, HIGH);
 delay(1000);
 digitalWrite(greenLED, LOW);
 delay (1000);
 } 

} 

}

void loop()
{
 readTags();
 
}

We don’t like it when you delete your first post so why have you done this to this one it looks like you were asking the same question.

Read up on how to use this forum and go back and edit the above post to use code tags.

That is two strikes against you, don’t make it a third.

I am sorry I was in a hurry and that is the main reason for all my wrong moves. I made a mistake because I deleted the message, it won't happened again. Deleted message was wrong formulated and the code was missing. My bad.

It is very difficult to read double-spaced text - please don't do it again.

The program in your Original Post seems to have nothing to do with your desired goal

when the first tag is read, LCD display the corresponding name of the product and the read time of this product with a note Start time. When the second RFID tag is read, the corresponding name of product is displayed on the LCD screen so as his reading time with a note Finished time. Difference between Finished time and Start time is calculated and displayed on the screen.

It just seems to be checking the IDs of 5 different tags.

It will be much easier to help if you make the first attempt at writing the program to do what you want.

I suggest that you don't use delay() anywhere in your program. Use millis() to manage all the timing as illustrated in Several Things at a Time

...R

 if(index == 14 && msg == tag1 ) 
 else if (index == 14 && msg == tag2)
 else if (index == 14 && msg == tag3)
 else if (index == 14 && msg == tag4)
 else if (index == 14 && msg == tag5)

Just how many times do you need to compare index to 14? It's nice that you know how to write compound if statements, but sometimes its better to use nested if statements. Like now.

Somewhere/somehow, you need to keep track of which tag was scanned this time, and, for that tag, record the time, either as the start time or the end time. The simplest way to do that is to put all the known tags in an array, and have an array of start times (initialized to 0). You may, or may not, want to have an array of end times.

The readTags() function should do JUST that.

Write another function to compare the tag just read to those in the knownTags array. When you find a match, the tag is either being presented to start the timer or to end the timer. Which it is depends on whether there is a start time recorded. If startTimes[n] is 0, where n is the index of the tag in the knownTags array, then the timer should be started. If startTimes[n] is not 0, then the timer should be stopped, by recording an end time, calculating the interval, and clearing the start time.

Thank you very very much on your answer and your suggestions.
I think that I'am on the good way to make a code that I need.
I can post "code try" when I finish it.

Any critics or good advice are always welcome.