Go Down

Topic: Code share: some of my util classes (Read 2 times) previous topic - next topic

obiwanjacobi

I am a C# programmer and am used to work with classes and Object Orientation (OO).
So I created some simple classes to encapsulate some essentials.

I've attached a .zip file called Libraries. Unzip it in your Arduino folder in My Documents. It contains 3 mini libs: AnalogInput, DigitalInput and DigitalOutput.

Please read the header files for more information on the specific classes.

I find them useful and hope others will too.

Enjoy,
Marc Jacobi
Netherlands.

robtillaart

I like the idea of a flag that the value has changed.

idea:
I am missing code to enable the internal pull up resistor

Maybe you can explain the rationale behind the details of these classes ?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

obiwanjacobi

It is a work in progress. I build what I need but make sure I can extend later.
BTW: there is a method enableInternalPullup on the DigitalInput class ;)

I've created these classes as an exercise (in Arduino dependency management ;-) ) and because I don't like all the static and sequential stuff that seems to be the norm. I understand that it is convenient for beginners, but I am an OO programmer 8) and like it when I don't have to keep all the low level details in my head  XD I truly believe that you get better code if you use OO responsibly. But I also understand that it is not the only variable on a platform like the Arduino. That is why I want to learn a bit more on code optimization first, before getting too far ahead of myself. :D

Also being a beginner in experimenting with the Arduino (although I had previous experience with other types of MCU's) I quickly found that I was repeating myself (in code). To me, that is always a sign 'something needs to be done'. This is my first pass at it.

I hope more people will see its value and find these classes useful.

robtillaart

Quote
BTW: there is a method enableInternalPullup on the DigitalInput class

Sorry, I missed it in the quick look

Quote
I truly believe that you get better code if you use OO responsibly

But allways remember that OO is a tool not the goal itself. And any technique should be used responsibly.

Quote
all the static and sequential stuff that seems to be the norm.

Not necessary the norm but sometimes the only way to get the functionality needed packed in the memory available.

That all said, keep posting your work as it is allways inspiring to see other peoples code.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

obiwanjacobi


Not necessary the norm but sometimes the only way to get the functionality needed packed in the memory available.


Can you elaborate on that? I have no idea (yet) on how efficient the compiler packs down the code and how smart it is in optimizing.
What I saw was staticly defined class instances just so the MyLib.someFunction (like SPI.write or whatever) syntax can be used. Is the compiler smart enough not to package up unused code? Otherwise if you don't use those statics (because you need more than one instance?) they will only take up  memory space.

Go Up