Library Error

I was trying to write a library for a seven segment display when i got the error: “Expected unqualified-id before ‘.’ token”. Here is my code:

Sketch:

#include <SevenSegment.h>

int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;

void setup(){
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
}

void loop(){
  SevenSegment.zero();
  delay(1000);
  SevenSegment.one();
  delay(1000);
  SevenSegment.two();
  delay(1000);
  SevenSegment.three();
  delay(1000);
  SevenSegment.four();
  delay(1000);
  SevenSegment.five();
  delay(1000);
  SevenSegment.six();
  delay(1000);
  SevenSegment.seven();
  delay(1000);
  SevenSegment.eight();
  delay(1000);
  SevenSegment.nine();
  delay(1000);
}

Source:

/*
SevenSegment.cpp - Librery for controlling multi-digit seven segment dislays.
Created November 3, 2011.
*/

#include "WProgram.h"
#include "SevenSegment.h"

void SevenSegment::alllow(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::one(){
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void SevenSegment::two(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}

void SevenSegment::three(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}

void SevenSegment::four(){
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::five(){
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::six(){
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::seven(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void SevenSegment::eight(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::nine(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::zero(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}

void SevenSegment::d11(){
  digitalWrite(dig1, HIGH);
}
  
void SevenSegment::d10(){
digitalWrite(dig1, LOW);
}

void SevenSegment::d121(){
digitalWrite(dig2, HIGH);
}

void SevenSegment::d20(){
digitalWrite(dig2, LOW);
}

Header:

#ifndef SevenSegment_h
#define SevenSegment_h

#include "WProgram.h"

class SevenSegment
{
public:
void alllow();
void one();
void two();
void three();
void four();
void five();
void six();
void seven();
void eight();
void nine();
void zero();
void d11();  
void d10();
void d121();
void d20();
private:
};

#endif

How can I fix this?

I was trying to write a library for a seven segment display when i got the error: "Expected unqualified-id before '.' token".

Was this all the error message you got? Whenever I write a library I get an extensive list of error messages that I slowly have to fix. These always say something along the lines of "In file Segment.cpp:". This will help to find the error, so please copy the whole message.

Onions.

Have you declared an object of type SevenSegment?

To Onions: Yes, that is the only error I get, but I get it like ten times.
To AWOL: Probably a noob thing to say but... How do you do that?

SevenSegment mySevenSeg;

(You may want to ask yourself why there are ten error messages)

Yes, that is the only error I get, but I get it like ten times.

Perculiar...

Added to what AWOL said, you need to create an instance of that object, as shown in his post. What this does is turns the class from a list of instructions to an object. (Syntax: Class-name object-name). You can then access variables and functions in the class by going class-name.variable-or-function. If you used the initialiser AWOL said, that would be mySevenSeg.one(), or similar.

Onions.

Changed my code. Gives the error "no matching function for call to 'SevenSegment::SevenSegment(int,
int, int, int, int, int, int, int, int, int,)'"

/*
SevenSegment.cpp - Librery for controlling multi-digit seven segment dislays.
Created November 3, 2011.
*/

#include "WProgram.h"
#include "SevenSegment.h"

SevenSegment::SevenSeg(int a, int b, int c, int d, int e, int f, int g, int dig1, int dig2){
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dig1, OUTPUT);
pinMode(dig2, OUTPUT);


void SevenSegment::alllow(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::one(){
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void SevenSegment::two(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}

void SevenSegment::three(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}

void SevenSegment::four(){
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::five(){
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::six(){
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::seven(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void SevenSegment::eight(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::nine(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void SevenSegment::zero(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}

void SevenSegment::d11(){
  digitalWrite(dig1, HIGH);
}
  
void SevenSegment::d10(){
digitalWrite(dig1, LOW);
}

void SevenSegment::d121(){
digitalWrite(dig2, HIGH);
}

void SevenSegment::d20(){
digitalWrite(dig2, LOW);
}

Header:

#ifndef SevenSegment_h
#define SevenSegment_h

#include "WProgram.h"

class SevenSegment
{
public:
void alllow();
void one();
void two();
void three();
void four();
void five();
void six();
void seven();
void eight();
void nine();
void zero();
void d11();  
void d10();
void d121();
void d20();
private:
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int dig1;
int dig2;
};

#endif

You may want to check that opening braces match closing braces, and that constructor name matches class name.

You are right, I did forget those braces, but I fixed them and the same error pops up.

And the constructor?
You may wish to skip the constructor, and just go for a 'begin' method instead.

Don't I need the constructor to initialize the pins I use in the source?

But you've got a mix of global and parameters to name the pins.
That way lie bugs.
The only reason you would need constructor would be if you had the pin numbers as private constant class members, when the constructor would have an initialiser list.
If all your constructor is doing is setting pin modes, you could do that in a 'begin' method.

But first, you need to sort out encapsulation.