Library help please

Greetings all,
This is my first pos in the Forum.
I am have been playing around with the Arduino for a couple of months now and I am now getting into GLCD’s and writing libraries. My first attempt at intergrating the two is not so sucessful. I am using Sparkfun’s Serial backpack with “Huge GLCD”. I am trying to simplify the programming by writing a library for its more complex commands.
I have never attempted anything like this before, but the tutorial on the main page seemed easy enough.
Long story short, my library/sketch doesn’t compile.
I am looking for any help from the community. Attached is a copy of my program.

/*Library for Sparkfun GLCD Backpack
lets see if this will work*/


#ifndef Slcd_h
#define Slcd_h

#include "WProgram.h"

class Slcd
{
  public:
  void clear();
  void demo();
};

#endif
/*.CPP file for Slcd library
*/

#include "WProgram.h"
#include "Slcd.h"

Slcd::Slcd()
{
  Serial.print();
}

void Slcd::clear()
{
Serial.print(0x7C, BYTE);
Serial.print(0x00, BYTE);
}

void Slcd::demo()
{
Serial.print(0x7C, BYTE);
Serial.print(0x04, BYTE);
}
[#include <Slcd.h>


void setup()
{
  Serial.begin(115200);
}

void loop()
{
  Slcd.demo();
  delay(10000);
  Slcd.clear();
  Serial.print("test");
  delay(5000);
  Slcd.clear();
}/code]

Add to h:

public: Slcd(); //constructor

Tried that, no luck but I did get a few more messages after it tried to compile. However, I could not make heads or tails of them. thanks, Mike

I did get a few more messages after it tried to compile. However, I could not make heads or tails of them.

Post them, and your updated code and sketch. The messages are cryptic, but not random. I'm sure that we can help you get them sorted out in less that 42 iterations.

By the way, in the sketch, you need to call methods on an instance of the class:

Slcd myLcd;

void loop()
{
   myLcd.demo();
}

C:\Users\bigmike\Documents\arduino-0018\libraries\Slcd\Slcd.cpp:8: error: expected unqualified-id before '{' token

Here it what it is saying now. I must have changed something and not known about it. Here is the current instance of my .h and .cpp.

/*.CPP file for Slcd library
*/

#include "WProgram.h"
#include "Slcd.h"

Slcd::Slcd
{
  Serial.print();
}


void Slcd::clear()
{
Serial.print(0x7C, BYTE);
Serial.print(0x00, BYTE);
}

void Slcd::demo()
{
Serial.print(0x7C, BYTE);
Serial.print(0x04, BYTE);
}
/*Library for Sparkfun GLCD Backpack
lets see if this will work*/


#ifndef Slcd_h
#define Slcd_h

#include "WProgram.h"

class Slcd
{
  public:
  Slcd();
  void clear();
  void demo();
};

#endif

Thanks all for the help, Mike

Slcd::Slcd
{
  Serial.print();
}

The compiler is expecting the function declaration to end with some parentheses enclosing the argument list. It is complaining that it found the { for the body of the function before it found the arguments. The () are not optional.

here is what my code looks like now.

Slcd::Slcd()
{
  Serial.print();
}

and here is what the compiler is saying.

C:\Users\bigmike\Documents\arduino-0018\libraries\Slcd\/Slcd.h:10: error: forward declaration of 'struct Slcd'

I copied your header file, source file, and sketch. I was able to compile and link, on Aruino 0017. I needed to make a few minor changes.

WProgram.h does not live in the sketch directory, so

#include [glow]"[/glow]WProgram.h[glow]"[/glow]

fails.

This

#include [glow]<[/glow]WProgram.h[glow]>[/glow]

works fine, however.

The error messages are very cryptic, to say the least.

I also had to change the sketch. It now looks like this:

#include "slcd.h"
#include <WProgram.h>

[glow]Slcd myslcd;[/glow]

void setup()
{
 Serial.begin(115200);
}

void loop()
{
 [glow]myslcd[/glow].demo();
 delay(10000);
 [glow]myslcd[/glow].clear();
 Serial.print("test");
 delay(5000);
 [glow]myslcd[/glow].clear();
}

I had used lower case names for the source and header files, so will need to change the slcd name back to Slcd.

Finally, Serial.print(); in the constructor threw a fit. Serial.print(“Constructing”); worked, but…

Since the class is instantiated before Serial.begin is called in setup(), don’t expect to actually get any output.

Finally, you should implement a begin method, and call it on the instance, in setup, instead of actually doing anything in the constructor (if you need to actually do anything in the constructor).