RC522 RFID Reader waiting for TAG, when I need Main Loop to run constantly

Thread Starter

combover61

Joined Oct 16, 2015
18
Main Loop worked great.

RFID read, write and display worked great.

Combined the two, and the RFID is waiting for a TAG to be read ... preventing the Main Loop from running constantly.

How can I have the RFID reader constantly available for new TAGs, yet keep my Main Loop running constantly?

Code below, RFID library that is called is attached:
C:
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

}
Mod edit: Added code tags
 

Attachments

Last edited by a moderator:

MrSoftware

Joined Oct 29, 2013
1,610
Using interrupts is a great idea, and alternatively there might be a way to make a non-blocking read call to your device. Perhaps poll the device to see if data is waiting. You would have to see the docs for the device or its driver/library to determine this.
 
Top