Hello!
I have a few questions regarding Arduino libraries. I've been trying to implement my own library into my code, and I've been getting these errors:
sketch_sep24a.cpp.o: In function
__static_initialization_and_destruction_0': D:\Users\Arduino\arduino-1.0.5/sketch_sep24a.ino:58: undefined reference to
PumpControl::PumpControl(int)'
sketch_sep24a.cpp.o: In functionloadSDConfig()': D:\Users\Arduino\arduino-1.0.5/sketch_sep24a.ino:193: undefined reference to
PumpControl::setTimers(int, int, int)'
I've build the library as the Arduino reference dictates:
#ifndef PumpControl_h
#define PumpControl_h
#include "Arduino.h"
class PumpControl {
public:
// On which pin the relay for the pump is connected.
PumpControl(int relayPin);
// Starting the relay on the defined pin.
void startRelay();
// Check of the parameters are within the configuration bounds.
boolean checkPumpConfig(int pumpOnPerMins, int delayPumpSec, int delayPumpMins);
// Sets the parameters as the objects configuration
void setTimers(int pumpOnPerMins, int delayPumpMins, int delayPumpSec);
// Main function to control the pump, needs the current time given as hour, minutes and seconds.
void controlPump(int hour, int mins, int secs);
// Getter for mainPumpTimer
int getMainPumpTimer();
// Setter for mainPumpTimer
void setMainPumpTimer(int mins);
private:
int _relayPin;
int nextPumpM;
int nextPumpS;
int mainPumpTimer;
boolean pumpOnce;
boolean setMPTimerOnce;
};
#endif
And:
#include "Arduino.h"
#include "PumpControl.h"
PumpControl::PumpControl(int relayPin){
_relayPin = relayPin;
}
void PumpControl::startRelay(){
pinMode(_relayPin, OUTPUT);
}
void PumpControl::setTimers(int pumpOnPerMins, int delayPumpMins, int delayPumpSec){
if(checkPumpConfig(pumpOnPerMins, delayPumpMins, delayPumpSec)){
this.pumpOnPerMins = pumpOnPerMins;
this.delayPumpMins = delayPumpMins;
this.delayPumpSec = delayPumpSec;
}
}
boolean PumpControl::checkPumpConfig(int pumpOnPerMins, int delayPumpSec, int delayPumpMins){
//Check pump config
if( delayPumpMins <= 0 || delayPumpMins > 59 ){
if(delayPumpSec > 0){
return false;
}
} else if( delayPumpSec <= 0 || delayPumpSec > 59 ){
if(delayPumpMins > 0){
return false;
}
} else if( pumpOnPerMins < 1 || pumpOnPerMins > 59 ){
return false;
} else {
return true;
}
} etc. etc.
And the main code looks like this:
#include <PumpControl.h>
PumpControl pumpOne(2);
void setup(){
pumpOne.startRelay();
pumpOne.setMainPumpTimer(mins());
}
void loadSDConfig(){
File config;
char cfgarray[5];
int pumpOnPerMins;
int delayPumpMins;
int delayPumpSec;
// SD card initiation
Serial.print("Initializing SD card...");
pinMode(53, OUTPUT);
if(!SD.begin(4)){
Serial.println("initialization failed");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
return;
}
Serial.println("initialization complete");
if(SD.exists("config.ini")) {
Serial.println("Loading configuration,....");
}
else {
Serial.println("Configuration not present on sd card.");
}
// open the config file
config = SD.open("config.ini");
// if the file is available
if (config) {
for(int i = 0; config.available(); i++) {
cfgarray[i] = config.read(); // data saved to config array
}
config.close(); // closed the SDCard file
}
// if the file isn't open, pop up an error:
else {
Serial.println("Error opening configuration file.");
}
// Load config data into code
sysMode = cfgarray[0] - 48;
sensorAmount = cfgarray[1] - 48;
update2Server = cfgarray[2] - 48;
pumpOnPerMins = ((cfgarray[3] - 48) * 10) + cfgarray[4] - 48; // pump on every 1st decimal + 2d decimal mins
delayPumpMins = ((cfgarray[5] - 48) * 10) + cfgarray[6] - 48; // minutes delay
delayPumpSec = ((cfgarray[7] - 48) * 10) + cfgarray[8] - 48; // seconds delay
//Setting the pump timers for pumpOne Object
pumpOne.setTimers(pumpOnPerMins, delayPumpMins, delayPumpSec);
}
Does anyone know why i keep getting these "undefined reference to" errors?
Thanks for any tips!