Timer2 Library

Hello,

I have looked over the web to find out how to use timer2 on arduinos but the libraries that I found did not quite suit me needs.

I have therefore created a library using mstimer2 and timerone libraries as templates. but I am not sure if what I have created is sensible.

I would therefore be really grateful if members here could peer review the library and feedback and improvement or modification as required to have a decent working library.

Many thanks,
Sherzaad

TimerTwo.h (1002 Bytes)

TimerTwo.cpp (9.76 KB)

The first thing that I would look at is "Does the library meet all the requirements?". Since I have no idea what your requirements were, it does not see likely that I could provide much useful feedback.

What I can tell you
is that your indenting leaves a lot to
be desired.

You have methods that are implemented in the header file. That is NOT a good idea.

If you just absolutely can not stand to put the { on new lines, where they belong, atleastseparatethe{fromtherestofthestatement.

extern Timer2 Timer2;

Having a variable (instance) with same name as the class is not a good idea.

Part of the documentation needs to include a discussion of what other libraries (that you know of) use timer2, and what the impacts of using your class will be.

Thank you for for feedback PaulS

initially I intended to make it a purpose specific library but then thought why not make it a generic library that could be used to make timer2 more accessible same as the library created for timer1.

Hence me posting it here for discussion. the library is intended for all.

I know that tone uses timer2. so my guess is that unless you are using that function in your arduino code, it should be fairly safe to access and use timer2

what I want to know if wherether there are any restrictions in using timer2 - for example prescalers and the other configuration setup I have applied in the files that may be violated AND if the library coding (not formatting) is sound ie will not raise errors.

I have read somewhere that "Placing nearly all the code in this .h file allows the functions to be inlined by the compiler. In the very common case with constant values the compiler will perform all calculations and simply write constants to the hardware registers".

This is my preference as I favour processing speed over compiled program size.