accessing global variable from an external class

Hi guys,

pretty new with arduino, nor I have a good knowledge in C#. so maybe what I'm about to ask is a very stupid question.

my project is to control 10 servos through the 74HC4017 decade counter chip. I've found an amazing tutorial here Drive 10 Servos using only 2 Arduino Pins - Blogs - diydrones it works!!! :wink:

anyway.. my goal is to control these servos using an external class written in C because I feel more confortable with OOP
the problem is: how the external class can access global variables or functions declared in the main sketch?
my only experience in programming is Processing and AS3, I know is possible using these tools. I guess is the same in arduino

thanks

the problem is: how the external class can access global variables or functions declared in the main sketch?

you need to pass them as parameter to the class so the class has a reference. Best known example might be the compare function as param in quicksort() See - qsort() sample program in C++ -

Thanks robtillaart,

I'm not sure I've understand what you mean. I had a look on the link, I'm pretty don't understand completely the code. Maybe I have to study a little more : :roll_eyes:
Anyway since an object's function is always called inside the loop, I can pass these variables through this function, yes this could be a solution but. I wondering if there is a way to access these variables (or functions); directly

thanks again

There are several tenets of OOP. One of them is encapsulation. A class should know only what it is told. Accessing directly, and yes, it could be done, global non-class data would violate this tenet.