This is, hopefully, a simple issue!
I'm trying to access my fully working libraries (fully compiles, and works with the hardware perfectly) from another library (Computer.h) to abstract it away from the Sketch.ino file.
LLRelay, and all my other libraries, work flawlessly when instanced/constructed/built/etc within the main Sketch.ino; however, when called within "Computer.h", there's issues.
I've been at this for most of the day trying different things, from instantiating the libraries in the header files, the *.cpp files, to within functions, to changing the scope and publicity/privacy of them - still no luck. See the (2 * "HERE -") comments for the errors.
Any help is greatly appreciated!
This is what I have managed to reduce it down to for debugging:
Sketch.ino
// Sketch.ino
#include "Computer.h"
Computer pc1;
void setup(){};
void loop(){
pc1.update();
};
Computer.h
// "../customLibs/Computer.h"
#ifndef Computer_lib
#define Computer_lib
#if(ARDUINO > 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class Computer {
public:
Computer();
void update();
private:
void fans();
};
#endif
Computer.cpp
// "../customLibs/Computer.cpp"
#include "Computer.h"
#include "src/relay/LLRelay.h" /* Potential culprit, I have tried many variations and locations for this to go, all with the same, or similar compilation errors */
/* HERE - "undefined reference to `LLRelay::LLRelay(unsigned char)'" */
LLRelay fan1(13); // fan1(uint8_t relayPin);
Computer::Computer(){
Serial.begin(9600);
};
void Computer::update(){
fans();
};
void Computer::fans(){
/* HERE - "undefined reference to `LLRelay::On()'" */
fan1.On();
};
LLRelay.h
// "../customLibs/src/relay/LLRelay.h"
#ifndef LLRelay_lib
#define LLRelay_lib
#if(ARDUINO > 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class LLRelay {
public:
LLRelay(uint8_t relayPin);
void On();
void Off();
private:
uint8_t _relayPin;
};
#endif
LLRelay.cpp
// "../customLibs/src/relay/LLRelay.cpp"
#include "LLRelay.h"
LLRelay::LLRelay(uint8_t relayPin){
_relayPin = relayPin;
pinMode(_relayPin, OUTPUT);
digitalWrite(_relayPin, LOW);
};
void LLRelay::On(){
digitalWrite(_relayPin, HIGH);
};
void LLRelay::Off(){
digitalWrite(_relayPin, LOW);
};