Я получаю сообщение об ошибке "слишком мало аргументов для работы" в моей программе. Я не знаю что не так
Я действительно новичок в Arduino и мне нужна помощь, я разработал программу и только на начальных этапах. Я получаю сообщение об ошибке "слишком мало аргументов для функции" bool findID (byte*) "). Мне нужно знать, что я делаю неправильно в этой программе, я использовал некоторые программы из нескольких разных источников, поэтому я получаю смущенный. Я ценю любую помощь, которую вы можете мне оказать.
Вот полная программа, пожалуйста, поймите, что она еще не закончена, и я просто пытаюсь убедиться, что она соответствует после каждого раздела, который я добавляю.
/*
* RFID stepper motor control
*
* Elegoo Mega 2560 R3
*
* MB102 Power Supply
* Connect to stepper controller 5v.
*
*
*
* RFID (RC522) scanner, and MIFARE tags.
* REMINDER: The scanner is a 3.3v device, don't connect it to 5v!
* PINS:
* RST = 5 (must be PWM)
* IRQ = NA
* MISO = 4
* MOSI = 3
* SCK = 2
* SDA = 6
*
* A stepper motor and controller.
* PINS:
* IN1 = 11
* IN2 = 8
* IN3 = 9
* IN3 = 10
*
* A basic passive buzzer/speaker
* Connected to pin 6 (must be PWM)
*
* A RGB LED
* PINS: (all PWM)
* R = 13
* G = 12
* B = 7
*/
#include <SPI.h>
#include <MFRC522.h>
#include <Stepper.h>
#include <SD.h>
#include <EEPROM.h>
#define readerRST 5 // This is the RST pin on your RFID reader.
#define readerSS 6 // And this is the SS pin on the RFID reader.
#define stepperIN1 11
#define stepperIN2 8
#define stepperIN3 9
#define stepperIN4 10
// The three pins for the RGB LED output.
#define ledR 13
#define ledG 12
#define ledB 7
#define STATUS_OK MFRC522::STATUS_OK
// How bright your RGB LED is.
#define color_intensity 50
boolean match = false; // initialize card match to false
boolean programMode = false; // initialize programming mode to false
int successRead; // Variable integer to keep if we have Successful Read from Reader
byte storedCard[4]; // Stores an ID read from EEPROM
byte readCard[4]; // Stores scanned ID read from RFID Module
byte masterCard[4]; // Stores master card's ID
MFRC522 mfrc522(readerSS, readerSS); // Create MFRC522 object for the card reader.
Stepper stepper(32,stepperIN1,stepperIN3,stepperIN2,stepperIN4);
void SetLed(int red,int green, int blue){
// Sets the colors of the RGB LED.
analogWrite(ledR,red);
analogWrite(ledG,green);
analogWrite(ledB,blue);
}
void setup() {
// Set our RGB LED pins to OUTPUT.
pinMode(ledR,OUTPUT);
pinMode(ledG,OUTPUT);
pinMode(ledB,OUTPUT);
Serial.begin(9600);
// card reader init
SPI.begin(); // Initialize SPI
mfrc522.PCD_Init(); // Initialize the reader.
// mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); // Maximize the reader's antenna gain.
SetLed(0,0,color_intensity);
Serial.println("Waiting for card...");
}
void Authenticated() {
// This is called when a valid ID is read.
Serial.println("Auth passed");
// Set the LED to green and start the motor.
SetLed(0,color_intensity,0);
stepper.setSpeed(500);
stepper.step(-580);
// Wait and step it back and set the LED back to blue.
delay(4000);
stepper.step(580);
SetLed(0,0,color_intensity);
}
void Failed() {
// Called when an invalid password is read.
Serial.println("Auth failed");
// Flash the LED red a couple times.
SetLed(0,0,0);
delay(100);
SetLed(color_intensity,0,0);
delay(100);
SetLed(0,0,0);
delay(100);
SetLed(color_intensity,0,0);
delay(100);
// And back to blue.
SetLed(0,0,color_intensity);
}
///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
int getID() {
// Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
// There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
// I think we should assume every PICC as they have 4 byte UID
// Until we support 7 byte PICCs
Serial.println(F("Scanned PICC's UID:"));
for (int i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
// getFilename(); // Get data ready
return 1;
}
void checkMaster() {
if (SD.exists("/SYS/master.dat")) { // Check if we have master.dat on SD card
Serial.print(F("Master Card's UID: ")); // Since we have it print to serial
File masterfile = SD.open("/SYS/master.dat"); // Open file
for (int i = 0; i < 4; i++) { // Loop 4 times to get 4 bytes
readCard[i] = masterfile.read();
Serial.print(readCard[i], HEX); // Actual serial printing of each byte
masterCard[i] = readCard[i]; // Prepare bytes for future comparing
}
Serial.println("");
masterfile.close(); // Close file
}
else {
Serial.println(F("No Master Card Defined"));
Serial.println(F("Scan A PICC to Define as Master Card"));
do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
// blueBlink(); // Visualize Master Card need to be defined
}
while (!successRead); //the program will not go further while you not get a successful read
File masterfile = SD.open("/SYS/master.dat", FILE_WRITE);
if (masterfile) {
Serial.println(F("Writing to master.dat..."));
masterfile.write(readCard, 4);
// close the file:
masterfile.close();
Serial.println(F("Master Card successfuly defined"));
} else {
// if the file didn't open, print an error:
Serial.println(F("error creating master.dat"));
// redBlink();
}
}
}
void ShowReaderDetails() {
// Get the MFRC522 software version
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print(F("MFRC522 Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (unknown)"));
Serial.println("");
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) {
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
// redSolid();
while (true); // do not go further
}
}
///////////////////////////////////////// Check Bytes ///////////////////////////////////
boolean checkTwo ( byte a[], byte b[] ) {
if ( a[0] != NULL ) // Make sure there is something in the array first
match = true; // Assume they match at first
for ( int k = 0; k < 4; k++ ) { // Loop 4 times
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
match = false;
}
if ( match ) { // Check to see if if match is still true
return true; // Return true
}
else {
return false; // Return false
}
}
////////////////////// Check readCard IF is masterCard ///////////////////////////////////
// Check to see if the ID passed is the master programing card
boolean isMaster( byte test[] ) {
if ( checkTwo( test, masterCard ) )
return true;
else
return false;
}
//////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
void readID( uint8_t number ) {
uint8_t start = (number * 4 ) + 2; // Figure out starting position
for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes
storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array
}
}
///////////////////////////////////////// Add ID to EEPROM ///////////////////////////////////
void writeID( byte a[] ) {
if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before!
uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts
num++; // Increment the counter by one
EEPROM.write( 0, num ); // Write the new count to the counter
for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position
}
//successWrite();
Serial.println(F("Succesfully added ID record to EEPROM"));
}
else {
// failedWrite();
Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
}
}
///////////////////////////////////////// Remove ID from EEPROM ///////////////////////////////////
void deleteID( byte a[] ) {
if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card!
// failedWrite(); // If not
Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
}
else {
uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
uint8_t slot; // Figure out the slot number of the card
uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts
uint8_t looping; // The number of times the loop repeats
uint8_t j;
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards
slot = findIDSLOT( a ); // Figure out the slot number of the card to delete
start = (slot * 4) + 2;
looping = ((num - slot) * 4);
num--; // Decrement the counter by one
EEPROM.write( 0, num ); // Write the new count to the counter
for ( j = 0; j < looping; j++ ) { // Loop the card shift times
EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM
}
for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop
EEPROM.write( start + j + k, 0);
}
// successDelete();
Serial.println(F("Succesfully removed ID record from EEPROM"));
}
}
///////////////////////////////////////// Find Slot ///////////////////////////////////
uint8_t findIDSLOT( byte find[] ) {
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
// is the same as the find[] ID card passed
return i; // The slot number of the card
}
}
}
///////////////////////////////////////// Find ID From EEPROM ///////////////////////////////////
bool findID( byte find[] ) {
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
for ( uint8_t i = 1; i < count; i++ ) { // Loop once for each EEPROM entry
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
return true;
}
else { // If not, return false
}
}
return false;
}
void loop() {
do {
//checkClient();
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
if (programMode) {
// cycleLeds(); // Program Mode cycles through RGB waiting to read a new card
}
else {
// blueSolid(); // Normal mode, blue Power LED is on, all others are off
}
}
while (!successRead); // the program will not go further while you not get a successful read
if (programMode) {
if (isMaster(readCard)) { // If master card scanned again exit program mode
Serial.println(F("Master Card Scanned"));
Serial.println(F("Exiting Program Mode"));
Serial.println(F("-----------------------------"));
programMode = false;
return;
}
else {
if ( findID() ) { // If scanned card is known delete it
Serial.println(F("I know this PICC, removing..."));
removeID();
Serial.println(F("-----------------------------"));
}
else { // If scanned card is not known add it
Serial.println(F("I do not know this PICC, adding..."));
writeID();
Serial.println(F("-----------------------------"));
}
}
}
else {
if (isMaster(readCard)) { // If scanned card's ID matches Master Card's ID enter program mode
programMode = true;
Serial.println(F("Hello Master - Entered Program Mode"));
Serial.println(F("Scan a PICC to ADD or REMOVE"));
Serial.println(F("-----------------------------"));
}
else {
if ( findID() ) { // If not, check if we can find it
Serial.println(F("Welcome, You shall pass"));
granted(300); // Open the door lock for 300 ms
}
else { // If not, show that the ID was not valid
Serial.println(F("You shall not pass"));
denied();
}
}
}
}
// Look for new cards
// This is your MIFARE key, by default it's set to FFFFFFFFFFFF, but if you've changed it, you'll need to do that here.
// Otherwise your card will fail to read.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
byte block, len;
MFRC522::StatusCode status;
if ( ! mfrc522.PICC_IsNewCardPresent()) {
// No reason to go further if there's no card detected.
// Or the same card is detected without being removed.
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
// Bail out if it can't read the card for whatever reason.
return;
}
Serial.println("Card detected, scanning...");
// I'm storing the passcode (18 bytes) in block 4 of the card.
// Ideally, this would be spread across the card and encoded somehow.
byte passcode[18];
block = 4;
len = 18;
String code_found;
// Authenticate the card with your key, and proceed if you get an OK, you can add error checking here if you want.
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid));
if(status == STATUS_OK) {
// The authentication was good, so lets try to read the bytes from the block.
status = mfrc522.MIFARE_Read(block,passcode,&len);
if(status == STATUS_OK) {
// If the read is good, loop from 0 to 16 and build a string out of each byte in the block
for (uint8_t i = 0; i < 16; i++) {
if(!passcode[i] != 32) {
code_found += (char) passcode[i];
}
}
code_found.trim(); // Cut any fat here.
if(code_found == "VALID") {
// If the code is valid, we authenticate and run the motor, this should be turned into something properly secure, of course.
Authenticated();
}
else {
// If not, fail.
Failed();
}
}
}
// Now that everything is done, we're ready to shut the stepper control down, and wait for the next card.
// No cards can be read until this part of the code is reached.
delay(50);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}