Hello!
I'm working on a custom library and I need EEPROM functions in it... so I thought I could include it in my header file:
#ifndef MyTestLibrary_h
#define MyTestLibrary_h
#include "WProgram.h"
#include "..\EEPROM\EEPROM.h"
#define ADDRESS_LOCATION 511
#define DEFAULT_ADDRESS 0x03
class MyTestLibrary
{
public:
MyTestLibrary();
void begin();
private:
byte node_address;
void getNodeAddress();
void storeNodeAddress();
};
#endif
#include "MyTestLibrary.h"
MyTestLibrary::MyTestLibrary() {
}
void MyTestLibrary::begin() {
getNodeAddress();
}
void MyTestLibrary::getNodeAddress() {
node_address = EEPROM.read(ADDRESS_LOCATION);
if(node_address == 0xFF) {
node_address = DEFAULT_ADDRESS;
storeNodeAddress();
}
}
void MyTestLibrary::storeNodeAddress() {
EEPROM.write(ADDRESS_LOCATION, node_address);
}
But when I try to use it in a simple sketch:
#include <MyTestLibrary.h>
MyTestLibrary myTestLibrary;
void setup() {
myTestLibrary.begin();
}
void loop() {
}
the compiler complains about several errors:
MyTestLibrary\MyTestLibrary.cpp.o: In function `MyTestLibrary::storeNodeAddress()':
c:\arduino-0022\libraries\MyTestLibrary/MyTestLibrary.cpp:24: undefined reference to `EEPROM'
c:\arduino-0022\libraries\MyTestLibrary/MyTestLibrary.cpp:24: undefined reference to `EEPROM'
c:\arduino-0022\libraries\MyTestLibrary/MyTestLibrary.cpp:24: undefined reference to `EEPROMClass::write(int, unsigned char)'
MyTestLibrary\MyTestLibrary.cpp.o: In function `MyTestLibrary::getNodeAddress()':
c:\arduino-0022\libraries\MyTestLibrary/MyTestLibrary.cpp:15: undefined reference to `EEPROM'
c:\arduino-0022\libraries\MyTestLibrary/MyTestLibrary.cpp:15: undefined reference to `EEPROM'
c:\arduino-0022\libraries\MyTestLibrary/MyTestLibrary.cpp:15: undefined reference to `EEPROMClass::read(int)'
The only solution so far is to include EEPROM also in my sketch...
Thanks!