Hey.
I've written a little class for a 7Segment-Display for myself and want to publish them on github. So I wrote it, wrote a litte(very easy^^) Simulation in Codeblocks and want to test it with the Arduino IDE. I have divide my little Class in 2(.h and .cpp) +1(for all the macros) and put it in a folder, which I include in the IDE. The SourceCode looks so( with the marks, where the other parts are included):
// PART 1: Called Template_7_Segment.cpp
#define GIVEN_OUT {for(int i = 0; i < 7; i++)digitalWrite(vars[i],number_lokal[i]);}
#define NUMBER1_lokal {byte number_lokal[7] = {LOW,HIGH,HIGH,LOW,LOW,LOW,LOW};GIVEN_OUT}
#define NUMBER2_lokal {byte number_lokal[7] = {HIGH,HIGH,LOW,HIGH,HIGH,LOW,HIGH};GIVEN_OUT}
#define NUMBER3_lokal {byte number_lokal[7] = {HIGH,HIGH,HIGH,HIGH,LOW,LOW,HIGH};GIVEN_OUT}
#define NUMBER4_lokal {byte number_lokal[7] = {LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH};GIVEN_OUT}
#define NUMBER5_lokal {byte number_lokal[7] = {LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH};GIVEN_OUT}
#define NUMBER6_lokal {byte number_lokal[7] = {LOW,LOW,HIGH,HIGH,HIGH,HIGH,HIGH};GIVEN_OUT}
#define NUMBER7_lokal {byte number_lokal[7] = {HIGH,HIGH,HIGH,LOW,LOW,LOW,LOW};GIVEN_OUT}
#define NUMBER8_lokal {byte number_lokal[7] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};GIVEN_OUT}
#define NUMBER9_lokal {byte number_lokal[7] = {HIGH,HIGH,HIGH,HIGH,LOW,HIGH,HIGH};GIVEN_OUT}
#define NUMBER0_lokal {byte number_lokal[7] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,LOW};GIVEN_OUT}
#define FAULT_7_Segment {digitalWrite(varDP,HIGH);}
// Part 2: called SevenSegment.h
class SevenSegment
{
// here is the include for the Template: #include "Template_7_Segment.cpp"
private:
byte output; // declaration for the content, which should be given out
byte vars[7];
byte varDP; // only the dotpoint gets an own variable, because I don't know when to use it(helpfully at 4x7Segments or something like that)
byte GND[2];
public:
SevenSegment(const byte [],const byte []); // given the Konstruktor all the cathodes off the 7segment in an array and the common grounds then also in an array
void writeDec(const byte&); // writes an Dec on the 7Segment
SevenSegment operator ++(int dummy); // overload the increment(postfix) operator for the SevenSegment class
void counting(const byte&); // counting from a overgiven number to zero by 1 Second
void writeChar(const byte&); // writes an letter or another sign to the 7-Segment(if its implemented in the template-file)
protected:
SevenSegment(const SevenSegment&); // having a copy-konstruktor, which only can used in the Class(in the case of development: I need it to overload the increment operator)
};
// Part 3, the implemantation: called SevenSegment.cpp
// #include "sevensegment.h"
SevenSegment::SevenSegment(const byte cathode[], const byte anode[])
{
for(int i = 0;i < 7;i++)
vars[i] = cathode[i];
varDP = cathode[7];
GND[0] = anode[0];
GND[1] = anode[1];
}
SevenSegment::SevenSegment(const SevenSegment ©)
{
for(int i = 0; i < 7; i++)
vars[i] = copy.vars[i];
varDP = copy.varDP;
GND[0] = copy.GND[0];
GND[1] = copy.GND[1];
output = copy.output;
}
void SevenSegment::writeDec(const byte &number)
{
switch(number)
{
case 0: NUMBER0_lokal output = 0; break;
case 1: NUMBER1_lokal output = 1; break;
case 2: NUMBER2_lokal output = 2; break;
case 3: NUMBER3_lokal output = 3; break;
case 4: NUMBER4_lokal output = 4; break;
case 5: NUMBER5_lokal output = 5; break;
case 6: NUMBER6_lokal output = 6; break;
case 7: NUMBER7_lokal output = 7; break;
case 8: NUMBER8_lokal output = 8; break;
case 9: NUMBER9_lokal output = 9; break;
default: FAULT_7_Segment break;
}
}
SevenSegment SevenSegment::operator ++(int dummy)
{
SevenSegment help = *this;
output++;
writeDec(output);
return help;
}
void SevenSegment::counting(const byte &number)
{
for(int i = number; i >= 0; i--)
{
writeDec(i);
i--;
delay(1000);
}
}
The problem is, that if I include this, the Compiler throw the exceptions, that all the types 'byte' in the definition of the Class(Part 2) aren't a type:
sevensegment.h:57: error: 'byte' does not name a type
But if I copy all these things into the Editor and run it then, there aren't mistakes! ( I use the last nightly build version, because I have the Arduino Due). So could anyone think about, why there is this kind of mistake?
P.S. Of course I know, that I could make something like#define byte {unsigned char}
, but I want to know, why there is such an stupid (linker) mistake...
Thank you!