creating library

#include <Wire.h>
class Lp3943
{
public:
Lp3943(char add);
Lp3943(char add,char pcs0,char pwm0,char pcs1,char pwm1);
void setprescaler(int p_add,char pcs);
void setpwm(int p_add,char pwm);
void ledstate(int led,int state);
private:
char address;
char array[4];
char setting[4];
};

Lp3943::Lp3943(char add)
{
Wire.begin();
address=add;
}
Lp3943::Lp3943(char add,char pcs0,char pwm0,char pcs1,char pwm1)
{
Wire.begin();
address=add;
setting[0]=pcs0;
setting[1]=pwm0;
setting[2]=pcs1;
setting[3]=pwm1;

}
void Lp3943::setprescaler(int p_add,char pcs)
{
if(p_add==0)
setting[0]=pcs;
else
setting[2]=pcs;
Wire.beginTransmission(address);
Wire.write(0x02+(p_add==0)?0x00:0x02);
Wire.write(pcs);
Wire.endTransmission();
}
void Lp3943::setpwm(int p_add,char pwm)
{
if(p_add==0)
setting[1]=pwm;
else
setting[3]=pwm;
Wire.beginTransmission(address);
Wire.write(0x03+(p_add==0)?0x00:0x02);
Wire.write(pwm);
Wire.endTransmission();
}
void Lp3943::ledstate(int led,int state)
{
char pos=led%4;
char add=led/4;
char l_bit;
l_bit=(state%2!=0)?1:0;
char h_bit=(state>1)?1:0;
array[add]=l_bit<<(2pos)|h_bit<<(2pos+0x01);
Wire.beginTransmission(address);
Wire.write(0x06+add);
Wire.write(array[add]);
Wire.endTransmission();
}
Lp3943 lp(0x60,0x80,0x40,0x80,0x80);
Lp3943 cp(0x61,0x80,0x40,0x80,0x80);
void setup()
{

}
void loop()
{

lp.ledstate(2,0);
cp.ledstate(1,0);
delay(30);
}

can anybody help me in creating a library from the above code.i tried but getting some error.

AFAIK you also need a keyword txt file.
Have a look in your existing library and get a peep on how the files are arranged.

I’ve tried your code submitted above, and it does compile all sailing flags no errors.

The keyword file is optional. I never

Anders53:
AFAIK you also need a keyword txt file.
Have a look in your existing library and get a peep on how the files are arranged.

I've tried your code submitted above, and it does compile all sailing flags no errors.

The keywords file is completely optional. I've never included one with any library I've written.

It looks like you are at the point where you are ready to put this into .h and .cpp files. The class definition goes in the .h file. All the function definitions go just like they are into the .cpp file. The sketch part, the two objects you create and setup and loop, all stay in the .ino file.

You mention errors. How can I help fix errors if you won't tell me what they are?

i have created the .h and .cpp file.the files are attached below.when i use library i get errors

D:\Arduino\libraries\Lp\Lp3943.cpp:1: error: stray ‘\357’ in program
D:\Arduino\libraries\Lp\Lp3943.cpp:1: error: stray ‘\273’ in program
D:\Arduino\libraries\Lp\Lp3943.cpp:1: error: stray ‘\277’ in program
D:\Arduino\libraries\Lp\Lp3943.cpp:1: error: stray ‘#’ in program
D:\Arduino\libraries\Lp\Lp3943.cpp:1: error: expected constructor, destructor, or type conversion before string constant
D:\Arduino\libraries\Lp\Lp3943.cpp:3: error: ‘Lp3943’ has not been declared
D:\Arduino\libraries\Lp\Lp3943.cpp:3: error: ISO C++ forbids declaration of ‘Lp3943’ with no type
D:\Arduino\libraries\Lp\Lp3943.cpp: In function ‘int Lp3943(char)’:
D:\Arduino\libraries\Lp\Lp3943.cpp:6: error: ‘address’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp: At global scope:
D:\Arduino\libraries\Lp\Lp3943.cpp:8: error: ‘Lp3943’ is not a class or namespace
D:\Arduino\libraries\Lp\Lp3943.cpp:8: error: ISO C++ forbids declaration of ‘Lp3943’ with no type
D:\Arduino\libraries\Lp\Lp3943.cpp: In function ‘int Lp3943(char, char, char, char, char)’:
D:\Arduino\libraries\Lp\Lp3943.cpp:11: error: ‘address’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp:12: error: ‘setting’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp: At global scope:
D:\Arduino\libraries\Lp\Lp3943.cpp:18: error: ‘Lp3943’ is not a class or namespace
D:\Arduino\libraries\Lp\Lp3943.cpp: In function ‘void setprescaler(int, char)’:
D:\Arduino\libraries\Lp\Lp3943.cpp:21: error: ‘setting’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp:23: error: ‘setting’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp: At global scope:
D:\Arduino\libraries\Lp\Lp3943.cpp:26: error: ‘Lp3943’ is not a class or namespace
D:\Arduino\libraries\Lp\Lp3943.cpp: In function ‘void setpwm(int, char)’:
D:\Arduino\libraries\Lp\Lp3943.cpp:29: error: ‘setting’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp:31: error: ‘setting’ was not declared in this scope
D:\Arduino\libraries\Lp\Lp3943.cpp: At global scope:
D:\Arduino\libraries\Lp\Lp3943.cpp:34: error: ‘Lp3943’ is not a class or namespace
D:\Arduino\libraries\Lp\Lp3943.cpp: In function ‘void ledstate(int, int)’:
D:\Arduino\libraries\Lp\Lp3943.cpp:41: error: ‘array’ was not declared in this scope

Lp3943.cpp (680 Bytes)

Lp3943.h (333 Bytes)

i have solved the error. problem was with cpp file saved as utf coding instead of ansi

Other things can give the "stray" error message. Sometimes when you cut-and-paste from a printed article into the IDE, you will see this error near a string literal. The reason is because the article used "right-leaning" and "left-leaning" double quote marks, which the IDE doesn't deal with very gracefully. Simply re-type the double quote marks and some of those errors will disappear.