I am new to arduino and I am trying to program my arduino to turn the servo motor 90 degrees when the correct card is read. However i get the ('getid' was not declared in this scope) error for readsucess = getid();. Any help will be much appreciated!!
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define RST_PIN 5 #define SS_PIN 53
MFRC522 rc(SS_PIN, RST_PIN);
byte readcard[4];
int readsucess;
void setup() {
Serial.begin(9600);
SPI.begin();
rc.PCD_Init();
rc.PCD_DumpVersionToSerial();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("Scan RFID card.");
lcd.setCursor(0,1);
}
void loop() {
readsucess = getid();
if (readsucess == 1){
lcd.clear();
lcd.print("UNLOCKED"); // CA F1 51 73
delay(2000);
reset();
}
else if (readsucess == 2){
lcd.clear();
lcd.print("CARD DECLINED ");
delay(1500);
reset();
}
void setup(){
readsucess =getid();
if (readsucess == 1) {
myservo.attach(33);
myservo.write(90);// move servo to center position ->90
}
}
}
}
int reset(){
Serial.begin(9600);
SPI.begin();
rc.PCD_Init();
rc.PCD_DumpVersionToSerial();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("Scan RFID card.");
lcd.setCursor(0,1);
}
int getid(){
if(!rc.PICC_IsNewCardPresent()){
return 0;
}
if (!rc.PICC_ReadCardSerial()){
return 0;
}
lcd.clear();
lcd.print("Scan RFID card.");
lcd.setCursor(0,1);
int count = 0;
for(int i=0;i<4;i++){
readcard_=rc.uid.uidByte*;_
_ if (i == 0){_ _ if (readcard == 202){ count = count + 1; } } if (i == 1){ if (readcard == 241){ count = count + 1; } } if (i == 2){ if (readcard == 81){ count = count + 1; } } if (i == 3){ if (readcard == 115){ count = count + 1; } } if (count == 4){ lcd.print(" CARD AUTHORISING");_ rc.PICC_HaltA(); _ delay(1000); return 1; } }_ rc.PICC_HaltA(); _ return 2; }*_
If you got past that error, there would be many more.
Your {}'s are messed up, there are functions defined inside of other functions (which would generate an error when you try to compile too, even if the other error didn't happen). That's what happened to getid() - it's defined inside of another function, which is invalid, so references to it throw an error.
Use CTRL+T to indent blocks and fix formatting - this will make it much easier to see places where you have mismatched braces, and fix them.
See how your code is messed up? There is no point in me copying it to my IDE to try to fix it. The reformatting of your code by the forum software can be avoided by posting in accordance with the forum guidelines posted here.
Part of the problem is that second setup() in the middle of loop()!
In file included from /Users/john/Documents/Arduino/sketch_feb21a/sketch_feb21a.ino:5:0:
/Users/john/Documents/Arduino/libraries/MFRC522/src/MFRC522Extended.h: In constructor 'MFRC522Extended::MFRC522Extended(uint8_t)':
/Users/john/Documents/Arduino/libraries/MFRC522/src/MFRC522Extended.h:81:44: warning: 'MFRC522::MFRC522(byte)' is deprecated: use MFRC522(byte chipSelectPin, byte resetPowerDownPin) [-Wdeprecated-declarations]
MFRC522Extended(uint8_t rst) : MFRC522(rst) {};
^
In file included from /Users/john/Documents/Arduino/sketch_feb21a/sketch_feb21a.ino:4:0:
/Users/john/Documents/Arduino/libraries/MFRC522/src/MFRC522.h:337:2: note: declared here
MFRC522(byte resetPowerDownPin);
^
/Users/john/Documents/Arduino/sketch_feb21a/sketch_feb21a.ino: In function 'void loop()':
sketch_feb21a:34:22: error: 'getid' was not declared in this scope
readsucess = getid();
^
sketch_feb21a:40:11: error: 'reset' was not declared in this scope
reset();
^
sketch_feb21a:47:11: error: 'reset' was not declared in this scope
reset();
^
sketch_feb21a:50:3: error: a function-definition is not allowed here before '{' token
}
void setup()
{
^
sketch_feb21a:126:1: error: expected '}' at end of input
}
^
exit status 1
'getid' was not declared in this scope