473,414 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How can I get my code to wait for me to scan my second RFID?

Is there a way for me to pause my code in the middle of the two if statements so I can scan the second RFID so the code can continue on to the second if statement with the information from the second RFID?
Expand|Select|Wrap|Line Numbers
  1. // Using Arduino Uno and RFIDs RC522
  2. #include <require_cpp11.h>
  3. #include <MFRC522.h>
  4. #include <deprecated.h>
  5. #include <MFRC522Extended.h>
  6.  
  7. #include <SPI.h>
  8. #include <MFRC522.h>
  9. #define SS_PIN 10
  10. #define RST_PIN 9
  11. MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
  12. int count = 0; 
  13. int greenLED = 5;
  14. int redLED = 6;
  15. int yellowLED = 7;
  16.  
  17. void setup()
  18. {
  19.   pinMode(greenLED, OUTPUT);
  20.   pinMode(redLED, OUTPUT);
  21.   pinMode(yellowLED, OUTPUT);
  22.  
  23.  
  24.   Serial.begin(9600);   // Initiate a serial communication
  25.   SPI.begin();      // Initiate  SPI bus
  26.   mfrc522.PCD_Init();   // Initiate MFRC522
  27.   Serial.println("Approximate your card to the reader...");
  28.   Serial.println();
  29.  
  30. }
  31. void loop()
  32. {
  33.   // Look for new cards
  34.   if ( ! mfrc522.PICC_IsNewCardPresent())
  35.   {
  36.     return;
  37.   }
  38.   // Select one of the cards
  39.   if ( ! mfrc522.PICC_ReadCardSerial()) {
  40.  
  41.     return;
  42.   }
  43.   //Show UID on serial monitor
  44.  
  45.   Serial.print("UID tag :");
  46.   String content= "";
  47.   byte letter;
  48.   for (byte i = 0; i < mfrc522.uid.size; i++) {
  49.  
  50.  
  51.      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  52.      Serial.print(mfrc522.uid.uidByte[i], HEX);
  53.      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  54.      content.concat(String(mfrc522.uid.uidByte[i], HEX));
  55.  
  56.   }
  57.   Serial.println();
  58.   //Serial.print("Message : ");
  59.   content.toUpperCase();
  60.   int count = 0;
  61.  
  62.   if (content.substring(1) == "89 E7 75 47") //change here the UID of the card/cards that you want to give access
  63.   {
  64.     Serial.println("Authorized access"); 
  65.     Serial.println();
  66.     digitalWrite(yellowLED, HIGH);
  67.     delay(1000);
  68.     digitalWrite(yellowLED, LOW);
  69.  
  70.   count = count + 1;
  71.   }
  72.  
  73.  else   {
  74.     Serial.println(" Access denied");
  75.     Serial.println();
  76.     digitalWrite(redLED, HIGH);
  77.     delay(1000);
  78.     digitalWrite(redLED, LOW);
  79.  
  80.  
  81. if (content.substring(2) == "F9 9A 76 47")
  82.   {
  83.     Serial.println("Authorized access"); 
  84.     Serial.println();
  85.     digitalWrite(yellowLED, HIGH);
  86.     delay(1000);
  87.     digitalWrite(yellowLED, LOW); 
  88.     count = count + 1;
  89.   }
  90.  else   {
  91.     Serial.println(" Access denied");
  92.     Serial.println();
  93.     digitalWrite(redLED, HIGH);
  94.     delay(1000);
  95.     digitalWrite(redLED, LOW);
  96.   }
  97.  
  98. if (count == 2 ) {
  99.     Serial.println(" Done");
  100.     Serial.println();
  101.     digitalWrite(greenLED, HIGH);
  102.     delay(3000);
  103.     digitalWrite(greenLED, LOW);
  104.  
  105. }
  106.  
  107. }
  108. }
  109.  
May 12 '19 #1
2 1322
Luuk
1,047 Expert 1GB
Is that not solved by a 'standard' while statement?

Expand|Select|Wrap|Line Numbers
  1. do
  2. {
  3.   //  whatever
  4. } while ( !condition );
  5.  
The condition is, in this case, 'scan second RFID succeeded'.
May 12 '19 #2
dev7060
636 Expert 512MB
I am not sure what you mean by "pause the code". The execution will always be stopped on using any function that requires user attention like inputs etc.

How is the "scan the second RFID" thing done? If that is something provided by the user, just insert the appropriate function between the two ifs. If that's something returned by a library function, just call that function after the first if. The program execution is sequential. Since you want the info of the second RFID before the second if, just make a way to fetch that info before going to the second if.

And then the code can continue on to the second if statement with the information of the second RFID.
May 12 '19 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: NotGiven | last post by:
I need to loop through some code but pause each time for about 1 second. how do I do this? Thanks.
4
by: MLH | last post by:
Best way to make Access 2.0 code wait 10 seconds before processing the next line??? For i=1 to whatever : next i is just too processor intensive. Isn't there something less taxing I can...
9
by: 466 | last post by:
/// headerfile; definition file for BBB class template <class CORE> class BBB : public CORE {}; /// another header file class AAA; template <class AAAclass BBB;
0
by: OldSchool | last post by:
Good day! I have problem dealing with Data recieving through use of RFID scanner. the Scenario is this, im going to scan the RFID and I will Recieved a Data from it and i will compare it in...
2
by: Ronald S. Cook | last post by:
I'm wanting to scan all folders and files under a specified path (e.g. C:\Files). I know using System.IO I can use Directory.GetFiles to get a list of files under a folder, but how do I get the...
3
by: =?Utf-8?B?Tkg=?= | last post by:
Hi, I am looking for some code that would scan a folder structure and files in those folders and display them on a web page so that people can click on the file links and open the files. There...
6
by: Tark Siala | last post by:
hi i'm using VS.NET 2005 +SP1 C#, and i connect access database by ADO.NET 2.0. i'm using Dataset to (insert,update,delete) and in get data i use (Datareader), but my problem when i do this: 1 -...
3
by: zyborg33 | last post by:
I am updating records in 2 tables, Employees and Projects with a new value for NAMEPHONE The code fails on the second update in one sub Private Sub cmdNewName_Click() Dim conDatabase As...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.