fiesta90150:
I would like to have like the first servo come on maybe every 2 hours for a certain amount of time (will depend on how much product i want to dose ), then the second one could maybe come on each hour and so on throughout the day. none of the servos will work at the same as another one. (its best too dose products one by one instead of all at the same time, unless its a two part product)
I have looked at different sketches for servos on the examples and the forum and the only one I honestly understand the best (not saying I understand it completely) is the one using the "delay"
this means to have a servo come on each hour I need to delay by 3600000ms ? if I'm correct?
OK, this is getting into a number of tutorials here but I will see what I can say.
It rather depends on what you mean by the servo "coming on".
Servos:
Servos are servo controlled motors. The electronics takes a a reference, a recurring pulse in the range 1 to 2 ms (milliseconds) with a "centre point" of 1.5 ms. It expects a pulse at least every 20 ms (50 Hz), and what it does in the absence of a pulse may be undefined - it might stay where it was last put, it might simply shut down as if it was turned off - which means that it will not resist any external force that might tend to move it - or it might decide to move fully in the direction corresponding to the shortest pulse length or attempt to keep moving beyond that which is clearly very bad!
Someone may (well) correct me on this, but unless you have tested exactly what your servos do when connected only to power and the signal line grounded - no pulses and not the same as low battery/ no power - it would certainly be wise to both ensure that the "end" position corresponds to no dose delivered and presume you need your program to be generating a continuous pulse stream no matter what else it is doing.
Now I was therefore not referring to having each servo perform its task in sequence, I was referring to just how you would arrange to continuously generate the stream of pulses every 20 milliseconds. The very last thing you want to do is to use a "delay" function for an hour. I was suggesting that it might be acceptable to use a delay function in the range of 1 to 2 ms - milliseconds - at the very maximum to generate each pulse to a given servo, one after the other.
Beyond that, as is repeatedly emphasised here, the "delay" function should be regarded as a "demonstrator" only, almost never to be used in a serious application. If you wish to use servos, they need to be serviced in the main "loop" function at least every 20 milliseconds, and anything else that you do in that loop must not delay matters for a significant proportion of that time. This is why it is stressed to avoid "blocking" function calls. This for example includes sending messages out on the serial line; you cannot safely use string sending functions because they may take many milliseconds to complete (even at higher baudrates), you need rather to arrange to send one character at a time as you traverse the "loop".
This comes down to code structure and is why you are referred to the "blink without delay" example and really do need to understand how it works. The general concept is that you are again, looping at a rapid rate, substantially faster than the events you need to either generate or assess. For inputs, you poll on each traversal of the loop and note (save) the time from one of your clocks (timer or millisecond counter which is updated by timer interrupts) comparing the time difference between one part of the event and the next. For outputs, you note the time when you started the event and determine at what time the event (such as a servo pulse) must be stopped, every time you pass this function in the loop you compare this to the current time such as to act upon it if that time has passed.
Of course, if you are generating servo pulses in this manner, they can easily be completely independent and may well overlap (without any interaction), or you could combine them into one piece of code to select one after the other by an array index - such an array could include the pin number for the servo and the current position expressed as a time in microseconds. Non-array variables would include the index to the servo presently being controlled, whether there was a pulse in progress and the time at which the current pulse should end. (In basic radio control, the end of the pulse for the first servo is the beginning of the pulse for the second and so on.)