I have a RFID reader which is connected to the Arduino.. and successfully receives tag number to serial monitor. But when I put the LED blink inside the loop, then the rfid reading is delayed: it receives tag numbers one by one after each blink.
Code is below. I think I should use multi-threading or interrupts, but I don't know how to do it.
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
pinMode(2, OUTPUT);
}
void loop() {
// blink led in pin 2
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
//Below Serial1.available() checks my rfid reader input signal and print on serial monitor of Arduino.. and Serial1 is on pin RX1 19 (RX1 19 is the default pin for serial1 defined by Arduino developers "http://arduino.cc/en/reference/serial#.Uyvbq6iSzIg") to which my rfid reader is connected
if (Serial1.available()) {
int i = Serial1.read();
Serial.print(i);
}
}