Apparently impossible ... need SPI to read RFID TAG in background of Main Loop

When I run this main loop, the loop waits for a RFID card to be read.
I need the program to loop constantly, and simply check the status of a card once per loop.

Been reading up on interrupts … yet not quite sure how to deal with this problem.
Could not find topic that addressed this specific issue.
Main loop code attached, as well as the library that it calls.

void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) { // Look for new RFID cards
return; }
if ( ! mfrc522.PICC_ReadCardSerial()) { // Select one of the RFID cards
return; }
mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); // Dump debug info about the card. PICC_HaltA() is automatically called.
if (mfrc522.uid.uidByte[0] == 0x61) { //
Serial.println(“blue”);
} else {
Serial.println(“card”);
}
Serial.println(); // Go to next line

// read the state of the vibration sensor latch
HITState = digitalRead(HITPin); // vibration sensor latched ON by debounce circuitry?
// if it is, the HITState is HIGH
if (HITState == HIGH) {
digitalWrite(CLEARHITPin, HIGH); // reset debounce circuitry
delay(500); // wait for 1/2 second
digitalWrite(CLEARHITPin, LOW); // complete reset of debounce circuitry

LEDS = LEDS-1; // set LEDS variable for number of LEDs to light

switch (LEDS) {
case 0:
analogWrite(BARGRAPHPin, 00); // 0 LEDs ON
break;
case 1:
analogWrite(BARGRAPHPin, 13); // 1 LED ON
break;
}
} else {
}
delay(50); // wait for 0.05 second
}

MFRC522.h (22.7 KB)

Apparently impossible ... need SPI to read RFID TAG in background of Main Loop

Given that the Arduino only has one processor and no operating system, doing anything "in the background" is impossible. Get over it.

When I run this main loop, the loop waits for a RFID card to be read.

It most certainly does not.

 if ( ! mfrc522.PICC_IsNewCardPresent()) {           // Look for new RFID cards
       return; }

YOU have told the Arduino to do NOTHING if there is no card present. STOP DOING THAT!

PaulS:
Given that the Arduino only has one processor and no operating system, doing anything "in the background" is impossible. Get over it.

This is a gross oversimplification, with an unnecessary withering tone, and on top of that, is wrong. Don't be a bully.

Many RTOS did things in the "background" for decades before multicore CPUs became the thing. That's what interrupts and timers are for.

And an OS is just a piece of software. So yes, things can be done "in the background" with an Arduino.

You may be interested in the demo Several Things at a Time

...R

Thank you all ...

PaulS ... in your cold straight forward way ... you nailed it ... I was unnecessarily waiting in "IF".