Can anyone send me a link tutorial about Arduino Object Oriented Programming? I want to learn Arduino, I am just a beginner.
-
1A little information that is missing from the answers: OOP has a small overhead because of a some boiler plate and object instantiation. This overhead is so marginal on desktops, servers and even mobile devices that we usually don't even mention it. On the arduino however, with it's severe restrictions on memory and computing power and where every byte may count, this overhead can become noticeable. Depending on your use case, this might be something to consider.– DouweCommented Aug 31, 2020 at 9:34
-
Agreed with @Douwe - the Arduino is not the place to lean OOP because it is not an environment where OOP can really leverage its power. OOP is a design strategy that came out of a need to simplify and abstract complex programs. The arduino is so small and so simple that programs never really get that complex to begin with. A desktop or mobile environment is a much better place to learn OOP because everything you're using in that environment are already objects - there's a whole framework to learn from. On the arduino there's nothing except what you build.– J...Commented Aug 31, 2020 at 11:35
4 Answers
"Arduino" is just plain old C++ with (in some cases) bits removed and some helper functions and classes.
For the smaller (lower powered AVR for example) there is no full STL in the C++ library, and some functions are of a reduced complexity (such as no floating point support in the printf
family of functions by default).
For OOP you don't need to know anything "Arduino" - it's just C++. Any C++ OOP tutorial will teach you what you need to know for Arduino OOP.
Have you programmed OOP before? For alot of projects you can get away with not knowing it.
I'll also point out that if you are just a beginner, I don't recommend starting off with OOP. Stick to simpler scripts (Trust me, OOP is a pain sometimes).
If you still INSIST on starting your arduino knowledge with OOP, look up "C++ classes" or "C++ OOP" as the default language that the arduino IDE uses is just a modified version of "C++"
-
Yes, I already done oop in different language like c#, I just want to familiarize the arduino c++ syntax. Commented Aug 30, 2020 at 14:28
http://paulmurraycbr.github.io/ArduinoTheOOWay.html really helped me understand what was happening. i had some previous oop expierence with java, but i still have a hard time using multiple files vs writing more methods in one file
I used OOP with C++ on an Arduino Due in an open source project.
Since I did not find any tutorila for the same the example might be helpful for You.
https://github.com/eschlot/Box-Joint-Jig-Control
W.r.t. the usability of OOP in embedded systems for scenarios like the above one there are plenty of good reasons to use OOP. A good example is the menu structure and the display control in the project. Nevertheless from my experience it is important to understand the effects of automatic object creation and tentative memory reorganization to the behavior of real time systems. This is much less predictable with C++ then with plain C and can be a reason to not use OOP in any real time system.