Ive seen lots of tutorials online and tried to follow along with them. I can get this project working when i use the example codes and modify them. However this code i wrote from scratch and cant seem to get it to work.
My serial monitor just show "GO" and then nothing after that. Any ideas how to fix this?
Im also getting an error when verifying "warning: invalid conversion from 'byte* {aka unsigned char*}' to 'byte {aka unsigned char}' [-fpermissive]
byte correcttag = taga;
^~~~
C:\Users\Escape Artist AZ\Documents\Sketches\RFID_Read_1-18-21\RFID_Read_1-18-21.ino: In function 'void checkcorrect()':
RFID_Read_1-18-21:69:33: error: invalid types 'byte {aka unsigned char}[int]' for array subscript
if (lasttag[0] == correcttag[0] ||
^
RFID_Read_1-18-21:70:33: error: invalid types 'byte {aka unsigned char}[int]' for array subscript
lasttag[1] == correcttag[1] ||
^
RFID_Read_1-18-21:71:33: error: invalid types 'byte {aka unsigned char}[int]' for array subscript
lasttag[2] == correcttag[2] ||
^
RFID_Read_1-18-21:72:33: error: invalid types 'byte {aka unsigned char}[int]' for array subscript
lasttag[3] == correcttag[3] )
^
exit status 1
invalid types 'byte {aka unsigned char}[int]' for array subscript
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
"
FULL CODE BELOW
#include <SPI.h>
#include <MFRC522.h>
//define used pins
byte sdapin = 53;
byte resetpin = 5;
byte greenpin = 8;
byte redpin = 9;
//begin scanning
MFRC522 scannerone(sdapin, resetpin);
MFRC522::MIFARE_Key structure;
//UIDs of each tag
byte taga[4] = {167, 195, 90, 214};
byte tagb[4] = {103, 218, 138, 198};
byte tagc[4] = {167, 98, 177, 199};
byte tagd[4] = {51, 231, 169, 61};
byte tage[4] = {32, 154, 91, 47};
byte tagf[4] = {32, 208, 250, 47};
//stores the UID of the last tag scanned
byte lasttag[4] = {00, 00, 00, 00};
byte correcttag = taga;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SPI.begin(); // Init SPI bus
scannerone.PCD_Init(); // Init MFRC522
for (byte i = 0; i < 6; i++) {
structure.keyByte[i] = 0xFF;
}
pinMode(greenpin, OUTPUT);
pinMode(redpin, OUTPUT);
Serial.println("GO");
}
void loop()
{
// put your main code here, to run repeatedly:
if (scannerone.PICC_ReadCardSerial() == 1)
{
Serial.println("Good");
if (scannerone.uid.uidByte[0] != lasttag[0] ||
scannerone.uid.uidByte[1] != lasttag[1] ||
scannerone.uid.uidByte[2] != lasttag[2] ||
scannerone.uid.uidByte[3] != lasttag[3] )
{
Serial.println("A new card has been detected.");
// Store NUID into lasttag array
for (byte i = 0; i < 4; i++)
{
lasttag[i] = scannerone.uid.uidByte[i];
Serial.println(scannerone.uid.uidByte[i]);
}
Serial.println(lasttag[1]);
checkcorrect();
}
}
}
void checkcorrect()
{
if (lasttag[0] == correcttag[0] ||
lasttag[1] == correcttag[1] ||
lasttag[2] == correcttag[2] ||
lasttag[3] == correcttag[3] )
{
digitalWrite(greenpin, HIGH);
}
}