Im trying to put some functions into another file/s

Program doesnt want to recognize the function inside its own file, neither in the main .ino file.
And i have a second question, how to use anothers(example: somestuff.h) file commands in a different .cpp file(someotherstuff.cpp) or in (main.ino).

Some help would be appreciated.

Console error log:

sketch\RFIDFunc.cpp: In function ‘void setup()’:

RFIDFunc.cpp:16:3: error: ‘dump_byte_array’ was not declared in this scope

dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);

^~~~~~~~~~~~~~~

sketch\RFIDFunc.cpp:16:3: note: suggested alternative: ‘__cpp_runtime_arrays’

dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);

^~~~~~~~~~~~~~~

__cpp_runtime_arrays

sketch\RFIDFunc.cpp: In member function ‘void RFIDFunc::Check()’:

RFIDFunc.cpp:62:7: error: ‘OpenDoor’ was not declared in this scope

OpenDoor();

^~~~~~~~

C:\Users\ville\Documents\Arduino\main_feb27a\main_feb27a.ino: In function ‘void loop()’:

main_feb27a:100:3: error: ‘Check’ was not declared in this scope

Check();

^~~~~

sketch\RFIDFunc.cpp:62:7: note: suggested alternative: ‘perror’

OpenDoor();

^~~~~~~~

perror

C:\Users\ville\Documents\Arduino\main_feb27a\main_feb27a.ino: In function ‘void MainPage()’:

main_feb27a:146:9: error: ‘OpenDoor’ was not declared in this scope

OpenDoor();

^~~~~~~~

C:\Users\ville\Documents\Arduino\main_feb27a\main_feb27a.ino:146:9: note: suggested alternative: ‘perror’

OpenDoor();

^~~~~~~~

perror

exit status 1
‘dump_byte_array’ was not declared in this scope

RFIDFunc.h:

#include <Arduino.h>
#include <SPI.h>
#include <MFRC522.h>
#include "RFIDFunc.h"
#include "DoorFunc.h"
MFRC522 mfrc522(53, 2); //SS_PIN, RST_PIN
MFRC522::MIFARE_Key key;

void setup() {
  //Init RFID Reader
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 card
  for (byte i = 0; i < 6; i++) {
        key.keyByte[i] = 0xFF;
  }
  Serial.print(F("Using key (for A and B):"));
  dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
  Serial.println();
}
void RFIDFunc::Check() {
  // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
  if ( ! mfrc522.PICC_IsNewCardPresent())
      return;

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
      return;
  byte sector         = 1;
  byte blockAddr      = 4;
  byte dataBlock[]    = {
     //Not important
  };
  byte trailerBlock = sector * 4 + 3;
  MFRC522::StatusCode status;
  byte buffer[18];
  byte size = sizeof(buffer);
  Serial.println(F("Current data in sector:"));
  mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
  Serial.println();

  // Check that data in block is what we have written
  // by counting the number of bytes that are equal
  Serial.println(F("Checking result..."));
  byte count = 0;
  for (byte i = 0; i < 16; i++) {
      // Compare buffer (= what we've read) with dataBlock (= what we've written)
      if (buffer[i] == dataBlock[i])
          count++;
          /*
          Serial.print("Buffer: ");
          Serial.print(buffer[i]);
          Serial.print("\n");
          Serial.print("DataBlock: ");
          Serial.print(dataBlock[i]);
          Serial.print("\n");
          */
  }
  Serial.print(F("Number of bytes that match = ")); Serial.println(count);
  if (count == 16) {
      OpenDoor();
  } else {
      Serial.println(F("Failure, no match :-("));
      Serial.println(F("perhaps you have the wrong card..."));
  }
  // Halt PICC
  mfrc522.PICC_HaltA();
  // Stop encryption on PCD
  mfrc522.PCD_StopCrypto1();
}
void RFIDFunc::dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

RFIDFunc.h:

#ifndef RFIDFunc_h
#define RFIDFunc_h

#include <Arduino.h>
#include <MFRC522.h>


class RFIDFunc
{
  public:
    void Check();
	  void dump_byte_array(byte *buffer, byte bufferSize);
	//unsigned char serNum[5];  
	//unsigned char AserNum[5]; 
	
  private:
    //int _chipSelectPin;
	//int _NRSTPD;
	
};

#endif

RFIDFunc.cpp (2.27 KB)

RFIDFunc.h (334 Bytes)

code is small, post with code tags directly in the forum. can't read easily from a mobile device and not every one is wiling to download stuff locally to help out. --> Make it easy for helpers to help you

Thanks, added.

Hum, why do you have setup() in the first file ?

You need a .ino with setup and loop, including your RFIDfuc.h and on the side a RFIDFunc.cpp which is the implementation of your class. Functions that are not part of the class should be forward declared as well in the .h

Im just not including the .ino file in this post, im thinking that i can make a second void setup for the .cpp file too(In my main .ino file i have void setup too)

Why do you want a setup there and who do you think is calling it ?

I want it to init SPI bus and rfid module and set the default key.

That should be part of a begin() function for your class or, given that you are using other libraries, you could consider letting the responsibility of activating SPI and RFID to the main code and have that main code hand over a working RFID reference to play with.

Yeah i got all that working thanks for saying that, i did a seperate init command and put that into main file.

great - have fun!