multifunction

how can i create a library so i can reduce my main code??
like include "masha.c" and "masha.h"..

like include "masha.c" and "masha.h"..

You include masha.h. That causes the compiler to compile masha.c. But, make life much easier on yourself, and name the file masha.cpp.

i d made a file that masha.h anda masha.cpp...but when i called it into my code there is a lot of erreur..i do not know whether i made mistake in my library or what...

we can't see your code so it can be anything from a typo to a logic error, or you have installed the library in the wrong place or ...

Please share all code (.cpp .h and example file)

Did you make a new tab in the IDE?

And why is this a poll? Should I vote for masha.c or masha.h? I can't decide.

#ifndef Timer_H
#define Timer_h

#include "WProgram.h"
class timer{
public:
enum TIMERSTATE {
MARCHE,
ARRET,
FINI
};

void TIM_Init(void);

void TIM_Stop(void);

void TIM_Start (void);

void TIM_Set(unsigned long ulTempo);

enum TIMERSTATE TIM_GetState(void) ;
};

#endif

this is my timer.h
and this is my code..

#include "Z:\arduino\code\Test_Timer2\timer.h"

int iEtat ;

void setup()
{
pinMode (13,OUTPUT);
iEtat = 0 ;
digitalWrite (13,iEtat);

TIM_Init() ;
TIM_Stop() ;
TIM_Set(5000) ;
TIM_Start() ;

}

void loop()
{
enum TIMERSTATE EtatDuTimer ;

while(1) {
EtatDuTimer = TIM_GetState() ;
if(EtatDuTimer == FINI) {
iEtat = ! iEtat ;
digitalWrite (13,iEtat);
TIM_Start() ;
}
}
}

////// i would like to declare this part as my timer.cpp..but the problems is when im doing this there will be a plenty of error..
struct Timer {
enum TIMERSTATE eEtat ;
unsigned long ulValue ;
unsigned long ulTempo ;
} ;

struct Timer gstTimer;

void TIM_Init(void) {
ASSR = 0 ; // Internal clock
TCCR2A = 0 ; // Normal mode pour le timer2
TCCR2B = 4 ; // Prescaler = 64 + Normal Mode
TIMSK2 = 1 ; // Valid interrupt on TOIE2
//TCCR2C
}

void TIM_Stop (void)
{
gstTimer.eEtat = ARRET ;
}

void TIM_Start(void)
{
gstTimer.eEtat = MARCHE ;
}

void TIM_Set(unsigned long ulTimer)
{
gstTimer.ulValue = 0 ;
gstTimer.ulTempo = ulTimer ;
}

enum TIMERSTATE TIM_GetState(void)
{
return gstTimer.eEtat ;
}

// interruption
ISR ( TIMER2_OVF_vect )
{
if (gstTimer.eEtat == MARCHE) {
gstTimer.ulValue ++ ;
if (gstTimer.ulValue >= gstTimer.ulTempo) {
gstTimer.eEtat = FINI ;
gstTimer.ulValue = 0 ;
}
}
}

can someone help me how can i transforme this part into timer.cpp??

////// i would like to declare this part as my timer.cpp..but the problems is when im doing this there will be a plenty of error..

And those errors are?

#include "Timer.h"
#include "WProgram.h"

void Timer::struct Timer {
enum TIMERSTATE eEtat ;
unsigned long ulValue ;
unsigned long ulTempo ;
} ;

struct Timer gstTimer;

void timer::TIM_Init() {
ASSR = 0 ; // Internal clock
TCCR2A = 0 ; // Normal mode pour le timer2
TCCR2B = 4 ; // Prescaler = 64 + Normal Mode
TIMSK2 = 1 ; // Valid interrupt on TOIE2
}

void Timer::TIM_Stop ()
{
gstTimer.eEtat = ARRET ;
}

void Timer::TIM_Start()
{
gstTimer.eEtat = MARCHE ;
}

void Timer::TIM_Set(unsigned long ulTimer)
{
gstTimer.ulValue = 0 ;
gstTimer.ulTempo = ulTimer ;
}

void Timer::enum TIMERSTATE TIM_GetState()
{
return gstTimer.eEtat ;
}

void Timer::ISR ( TIMER2_OVF_vect )
{

if (gstTimer.eEtat == MARCHE) {
gstTimer.ulValue ++ ;
if (gstTimer.ulValue >= gstTimer.ulTempo) {
gstTimer.eEtat = FINI ;
gstTimer.ulValue = 0 ;
}
}
}

when i made this part as timer.cpp..the rest of my code just be this rights::
#include "timer.h"

int iEtat ;
int i ;

void setup()
{
pinMode (13,OUTPUT); //declarer le pin 13 comme output(LED)
iEtat = 0 ;
digitalWrite (13,iEtat);

TIM_Init() ;
//ASSR = 0 ; // Internal clock
// TCCR2A = 0 ; // Normal mode pour le timer2
//TCCR2B = 4 ; // Prescaler = 64 + Normal Mode
//TIMSK2 = 1 ; // Valid interrupt on TOIE2
TIM_Stop() ;
TIM_Set(10000) ;
TIM_Start() ;

}

void loop()
{
enum TIMERSTATE EtatDuTimer ;

while(1) {

digitalWrite (13,iEtat);
EtatDuTimer = TIM_GetState() ;
if(EtatDuTimer == FINI) {
iEtat = ! iEtat ;
digitalWrite (13,iEtat);
TIM_Start() ;
}

}
}

my problem is,when i made this, its mentioned that all my Tim_Init etc has not been declared...am i doing wrong in my code or theres problems with my library??

TIM_Stop() ;
TIM_Set(10000) ;
TIM_Start() ;

You've defined these function as members of your timer class. As a result, they are only accessible through an instance of your timer class, ex:

timer myTimer;

myTimer.TIM_init();

That being said, since your timer class depends on the hardware timer, it's really not suited to creating multiple instances of timer. You can address that by making the timer class a singleton (not really recommended), or declaring all your methods as static, making them accessible without creating an instance of the class.

I'd personally recommend you go back to the basics and learn more about how to use classes in general. Google can provide plenty of online resources for doing so.

my problem is,when i made this, its mentioned that all my Tim_Init etc has not been declared...am i doing wrong in my code or theres problems with my library??

You have a class, timer, with a member method, TIM_Init. In your sketch, you are not creating an instance of the class, but you are trying to call members of that non-existent instance. You can't, obviously, do that.

If the purpose of the timer.h and timer.cpp files is not to create a class, why are you defining a class? It would seem that you simply need to get rid of the class definition.

When I did that, and included timer.h in timer.cpp, it all compiled fine.

im really soryy sir...im not so good in programming..i do not really understand

Learn C++. Then you will understand.

Google is your friend. Try Googling a few of the following:
learning c++
c++ tutorials
getting started with c++