I am brand new to coding in general and the spark photon in particular. I’ve got an MFRC522 RFID reader and the appropriate chips. My code will read chips and transmit their UID to the particle console, but I can’t figure out how to do much else. Currently I’m just trying to make it blink the Photon’s onboard LED a different color depending on whether a card is recognized or not. The current build causes the error message “rfidv2.cpp:76:14: error: ‘masterID’ was not declared in this scope”
My specific questions are:
- Why is this error occuring when masterID is declared during setup?
- What does the for statement in the middle do to the UID? I know the code won’t run right without it but I don’t understand why the compound addition operator is required.
3)Aside from the error, should this code cause the light to blink a different color if the card is the masterID card?
[code]#include “MFRC522/MFRC522.h”
/*
Function Core Pin MRFC522 Pin
Reset D2 RST
SPI SS D1 SDA
SPI MOSI A5 MOSI
SPI MISO A4 MISO
SPI SCK A3 SCK
*/
#define SS_PIN D1
#define RST_PIN D2
#define LED_PIN D7
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
mfrc522.setSPIConfig();
mfrc522.PCD_Init(); // Init MFRC522 card
RGB.control(true); // take control of onboard RGB led
String masterID = “77b392ab”;
}
void blinkAccess() {
RGB.color(0, 0, 255);
delay(150);
RGB.color(0, 0, 0);
delay(100);
RGB.color(0, 0, 255);
delay(150);
RGB.color(0, 0, 0);
}
void blinkDeny() {
RGB.color(0, 255, 0);
delay(150);
RGB.color(0, 0, 0);
delay(100);
RGB.color(0, 255, 0);
delay(150);
RGB.color(0, 0, 0);
}
void blinkReady() {
RGB.color(255, 0, 0);
delay(150);
RGB.color(0, 0, 0);
delay(100);
RGB.color(255, 0, 0);
delay(150);
RGB.color(0, 0, 0);
}
void loop() {
// Look for new cards
if ( mfrc522.PICC_IsNewCardPresent()) {
// Serial.println(“New card present…”);
if ( mfrc522.PICC_ReadCardSerial()) {
// Dump debug info about the card. PICC_HaltA() is automatically called.
String UID = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
UID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
UID += String(mfrc522.uid.uidByte[i], HEX);
}
mfrc522.PICC_HaltA();
Particle.publish("rfid-read", UID, 5, PRIVATE); // publish UID to rest of system
if (UID==masterID) {
blinkReady();
}
}
}
}
[/code]
Thanks for your time!