on(), off(), update(), and mlDose() are not static members of the class. Each instance of the class knows how to do those things. The class does not.
When the timer fires, which instance's method should it call? Since you can't tell the timer class that, you can tell it about static methods only. Then, in the static method, YOU must figure out which instance should execute some action, and make that instance execute some action.
Thought that every time I made an instance of the Valve class, a new timer would be attached to it But apparently it's better to use those libraries separately...?
Thought that every time I made an instance of the Valve class, a new timer would be attached to it
It is. But, look at this code:
_timer = _t.every(1, mlDose);
When _t determines that enough time has passed, it needs to call a function. You want it to call the mlDose() function. But, which of the possibly hundreds of instances of the mlDose() function?
I don't get why I should have more instances of that function when it belongs to the instance I created. Yes, if I create another instance of the class. But then I would reference from my main sketch to the function using
// instanciating
Valve valve;
// valve on
valve.on()
But _t.every(ms, function_to_call) is doing the job in a normal sketch, and I've tried before to call functions within the library from the library, so I don't understand how this is now different? Please have patience, soon it'll just "click" for me and I understand everything Sorry to be such a pain in the ass, and thank you for your help!
I don't get why I should have more instances of that function when it belongs to the instance I created.
There are multiple versions of the mlDraw() method if there are multiple instances of the Valve class. When the timer goes off, it doesn't know which of the (possibly) many mlDraw() functions to call.
I know that you think it should know to call the one that the belongs to the instance that the timer belongs to. But, the timer doesn't KNOW it belongs to an instance of a class. Therefore, it has no idea that it needs to tell the instance that it needs to do something.
That's why the method has to be static. If it is, the timer can tell the class to do something. Now, the class could keep track of all the instances, and ask each instance if it was it's timer that went off. If the instance reported yes, the class could tell the instance to do something.