HELP! I was given a standard Arduino Motor shield, attempted making a library...

Hello, My names Ryan. I have recently been given an Arduino Uno, and have Ubuntu 10.04.4, and attempted to make a library for the Motor Shield from Arduino. I have failed in my opinion. I have all my code AND error reports. If anyone can help, I would be glad!

Motor.h:
#ifndef Motor_h
#define Motor_h
#include <WProgram.h>
#include <Arduino.h>

class Motor
{
public:
void ~Motor();
void Motor(void);
void forward(int speed);
void backward(int speed);
void right(int speed);
void left(int speed);
void brake();

};
#endif

Motor.cpp:
#include <Motor.h>

#include <Arduino.h>

int speed;
const int dirB = 13;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int pwmA = 3;

void Motor::~Motor()
{
}

void Motor::Motor()
{

int speed;
const int dirB = 13;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int pwmA = 3;

pinMode(dirB, OUTPUT);
pinMode(dirA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
pinMode(pwmA, OUTPUT);
}

void Motor::brake()
{
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
}

void Motor::forward(int speed)
{
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
delay(10);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

digitalWrite(dirA, HIGH); //set A forward
digitalWrite(dirB, HIGH); // Set B forward
analogWrite(pwmA, speed);
analogWrite(pwmB, speed);
}

void Motor::right(int speed)
{
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
delay(10);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

digitalWrite(dirA, LOW);
digitalWrite(dirB, HIGH);
analogWrite(pwmA, speed);
analogWrite(pwmB, speed);
}

void Motor::left(int speed)
{
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
delay(10);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

digitalWrite(dirA, HIGH);
digitalWrite(dirB, LOW);
analogWrite(pwmA, speed);
analogWrite(pwmB, speed);
}

void Motor::backward(int speed);
{
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
delay(10);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

digitalWrite(dirA, LOW);
digitalWrite(dirB, LOW);
analogWrite(pwmA, speed);
analogWrite(pwmB, speed);
}

code to run motors:
#include <Motor.h>
Motor Motor;

void setup()
{

}

void loop()
{
Motor.forward(255);
}

Error report:
In file included from Tester.ino:1:
/home/chaos/Desktop/arduino-1.0.3/libraries/Motor/Motor.h:9: error: return type specification for destructor invalid
/home/chaos/Desktop/arduino-1.0.3/libraries/Motor/Motor.h:10: error: return type specification for constructor invalid

void Motor::~Motor()
{
}

void Motor::Motor()

/home/chaos/Desktop/arduino-1.0.3/libraries/Motor/Motor.h:9: error: return type specification for destructor invalid
/home/chaos/Desktop/arduino-1.0.3/libraries/Motor/Motor.h:10: error: return type specification for constructor invalid

Some compiler error messages can be really obscure.
Not here though.

Hint for the future: don't put "pinMode" in a constructor for the Arduino.

Please use code tags when posting code.

#include <WProgram.h>
#include <Arduino.h>

For any version of the IDE, only one of these exists. Why are you trying to include both, without the proper #ifdef directives?

Thank you! So if I just move the pinMode outside of Motor::Motor() the compiler should stop giving me errors? I'm a absolute noob at this business; I am a veteran C coder and I thought I was up to stuff. Thanks for clearing it up!

So if I just move the pinMode outside of Motor::Motor() the compiler should stop giving me errors?

No, but that is necessary.

Constructors and destructors do not have types, not even void.

I was supposed to be using Arduino.h but it got out of hand. Should I remove the WProgram include file?

So as for can you show me about what it should look like? I just started typing this yesterday, and have a deadline coming soon. Thanks

Should I remove the WProgram include file?

If you're using IDE 1.0 or later, yes.

Ok I can do that. Any other gaps in my program?

Apart from the limited scope of the constant declarations in the constructor?

Post your corrected code.

Motor.cpp :

#include <Motor.h>

#include <Arduino.h>

int speed;
const int dirB = 13;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int pwmA = 3;
 pinMode(dirB, OUTPUT);
  pinMode(dirA, OUTPUT);
  pinMode(pwmB, OUTPUT);
  pinMode(brakeA, OUTPUT);
  pinMode(brakeB, OUTPUT);
  pinMode(pwmA, OUTPUT);

void Motor::~Motor()
{
}

void Motor::Motor()
{

int speed;
const int dirB = 13;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int pwmA = 3; //Should I leave these guys? Or is that bad?


  
}

void Motor::brake()
{
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
}


void Motor::forward(int speed)
{
  digitalWrite(brakeA, HIGH);
  digitalWrite(brakeB, HIGH);
  delay(10);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);
  
  digitalWrite(dirA, HIGH); //set A forward
  digitalWrite(dirB, HIGH); // Set B forward
  analogWrite(pwmA, speed);
  analogWrite(pwmB, speed);
}

void Motor::right(int speed)
{
  digitalWrite(brakeA, HIGH);
  digitalWrite(brakeB, HIGH);
  delay(10);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);
  
  digitalWrite(dirA, LOW);
  digitalWrite(dirB, HIGH);
  analogWrite(pwmA, speed);
  analogWrite(pwmB, speed);
}

void Motor::left(int speed)
{
  digitalWrite(brakeA, HIGH);
  digitalWrite(brakeB, HIGH);
  delay(10);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);
  
  digitalWrite(dirA, HIGH);
  digitalWrite(dirB, LOW);
  analogWrite(pwmA, speed);
  analogWrite(pwmB, speed);
}

void Motor::backward(int speed);
{
  digitalWrite(brakeA, HIGH);
  digitalWrite(brakeB, HIGH);
  delay(10);
  digitalWrite(brakeA, LOW);
  digitalWrite(brakeB, LOW);
  
  digitalWrite(dirA, LOW);
  digitalWrite(dirB, LOW);
  analogWrite(pwmA, speed);
  analogWrite(pwmB, speed);
}

Motor.h :

#ifndef Motor_h
#define Motor_h
#include <Arduino.h>

class Motor
{
public:
void ~Motor();
void Motor();
void forward(int speed);
void backward(int speed);
void right(int speed);
void left(int speed);
void brake();



};
#endif

Hope i got that right!

Moderator edit: CODE TAGS

//Should I leave these guys? Or is that bad?

No, not bad, just pointless. Think about the scope of those declarations.

You've taken out the "pinMode"s completely, but they're necessary.
In Arduinoland, it's more usual to put them in a "begin" method.

Have a look at some of the provided libraries for hints.

A "Begin" method? Im sorry Im a absolute noob can you elaborate? Is that the same as a #define?

Classes like the "Serial" class have a "begin" method, because constructors are called before the hardware timers for the Arduino are setup, so setting the baud rate in a constructor would be pointless.
Same goes for "pinMode", so your constructor is either empty, or copies its parameters to its own private variables, but does nothing with them.
The "begin" method, then takes the private variables, and sets the "pinMode"s, or you supply the "begin" method with the pin numbers.

In your case, you're assuming a set of fixed pin numbers, so the "begin" method" would use those.

So should I add a part to my code that looks like:
void Motor::begin()
{
//Pinmodes here
}

Yes, that's correct.

Thank you AWOL! I finally got it fixed! I am going to be using this for a class project to show the use of libraries. With your permission I would like to give you credit!
Thanks,
Ryan Buxton :]