Hi,
I am new to C++ but I like to structure my application is such away that it will be as clean as possible. To start learning I decide to use the veeeery simple blinker program, although it should be very easy I am not able to get it running. I made a header file (blinker.h), a class file (blinker.cpp) and the application.cpp file, see the files below.
When I run the make command I get the following error:
> obj/src/application.o: In function `loop':
> /Users/henkgescher/Spark/Temporary/core-firmware/build/../src/application.cpp:12: undefined reference to `Blinker::on(int)'
> /Users/henkgescher/Spark/Temporary/core-firmware/build/../src/application.cpp:13: undefined reference to `Blinker::off(int)'
> obj/src/application.o: In function `__static_initialization_and_destruction_0':
> /Users/henkgescher/Spark/Temporary/core-firmware/build/../src/application.cpp:5: undefined reference to `Blinker::Blinker(int)'
> /Users/henkgescher/Spark/Temporary/core-firmware/build/../src/application.cpp:5: undefined reference to `Blinker::~Blinker()'
> collect2: error: ld returned 1 exit status
> make: *** [core-firmware.elf] Error 1
What is the mistake I make?
Thanks,
Henk.
application.cpp
/* Includes ------------------------------------------------------------------*/
#include “application.h”
#include “blinker.h”
Blinker myLed(D7);
void setup() {
}
void loop() {
myLed.on(5000);
myLed.off(1000);
}
blinker.h
/* Includes ------------------------------------------------------------------*/
#include "application.h"
#ifndef BLINKER_H
#define BLINKER_H
class Blinker {
public:
//Default Constructor
Blinker();
//Overload Constructor
Blinker(int);
//Destucture
~Blinker();
//Accessor functions
int getLed() const;
//Mutator functions
void setLed(int);
//@param int - define the led
//Function
void on(int);
//@param int - on time in msec
void off(int);
//@param int - off time in msec
private:
// Member variables
int definedLed;
protected:
};
#endif
blinker.cpp
/* Includes ------------------------------------------------------------------*/
#include "blinker.h"
Blinker::Blinker() {
}
Blinker::Blinker(int led) {
definedLed = led;
pinMode(definedLed, OUTPUT);
}
Blinker::~Blinker() {
}
int Blinker::getLed() {
return definedLed;
}
void Blinker::on(int time) {
digitalWrite(definedLed, HIGH);
delay(time);
}
void Blinker::off(int time) {
digitalWrite(definedLed, LOW);
delay(time);
}