Simple guidance for writing my first library

Hello experts,

I’m trying to write a library for controlling LEDs to simplify my code. after creating the header and source files i tried running this program:

#include <LED.h>
LED ledPin(13);
void setup()
{
}
void loop()
{
LED.on();
}

But I get the following error message:

TITLE: No matching function for call to ‘LED::LED(int)’
In file included from sketch_nov03b.cpp:1:
D:\Programs\arduino-1.0.1-windows\arduino-1.0.1\libraries\LED/LED.h:16: error: ISO C++ forbids declaration of ‘ledPin’ with no type
sketch_nov03b:2: error: no matching function for call to ‘LED::LED(int)’
D:\Programs\arduino-1.0.1-windows\arduino-1.0.1\libraries\LED/LED.h:12: note: candidates are: LED::LED()
D:\Programs\arduino-1.0.1-windows\arduino-1.0.1\libraries\LED/LED.h:12: note: LED::LED(const LED&)
sketch_nov03b.cpp: In function ‘void loop()’:
sketch_nov03b:10: error: expected unqualified-id before ‘.’ token

I’ve tried following two tutorials on Arduino’s main site but still no success. here’s the header .h file

#ifndef LED_h
#define LED_h
#include "Arduino.h"

class LED
{

public:
 ledPin(int pin);
 void blink(unsigned int uptime,unsigned int downtime,byte times=1);
 void on();
 void off();
private:
 int _pin;

};

#endif

and the source .cpp file:

#include "arduino.h"
#include "LED.h"

LED::ledPin(int pin)
{
  pinMode(pin, OUTPUT);
  _pin=pin;
}

void LED::blink(unsigned int uptime,unsigned int downtime,byte times=1)
{
  for (byte i=0;i<times;i++)
  {
  digitalWrite(_pin, HIGH);
  delay(uptime);
  digitalWrite(_pin, LOW);
  delay(downtime);
  }
}

void LED::on()
{
	digitalWrite(_pin, HIGH);
}

void LED::off()
{
	digitalWrite(_pin, LOW);
}

Please note that I have made countless adjustments and attempts but tried removing the .o files as described in one of the tutrials.

Any help is highly appreciated.

Thanks in advance,
Amin

The problem is in the declaration of ledPin in the library files. I think you meant to declare a constructor, in which case it must be called LED the same as the name of the class. However, it's not a good idea to make pinMode calls in constructors, because you can't guarantee the order in which constructors are called. Most device libraries provide a 'begin' function, and it's there that you call pinMode.

Thank you DC42,

I’m not sure I understand the mechanics here but it worked according to your suggestion!

Thanks again,

Also, try to get rid of those delay()s ASAP. Look at blink without delay example provided with the IDE.