How can the PWM pins 9 and 10 on the UNO be used normally after detaching a servo?
I have a motor drive that uses those pins for PWM control. The motor drive is fine, but If I make a call to a digital servo, it's routine runs, then I detach it but the pins are still set for the servo object, and the motor drive looses it's PWM signal.
Do I need to make a call to a destructor for the servo object itself, or is there an easier way?
Use pinMode() (pinMode() - Arduino Reference).
The reference page for the detach() method says this
detach()
Description
Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10 can be used for PWM output with analogWrite().
This would seem to indicate that the pins should be able to be used for PWM. Where and how are you setting the mode of the pins ?
If I make a call to a digital servo, it's routine runs, then I detach it but the pins are still set for the servo object
Can you clarify whether you want to use the same pins for servos and PWM or whether it is just the side effect of using the servo library that you are trying to circumvent ?
In your program you attach the servo only in setup(), which is the correct place but that means that you cannot use pins 9 and 10 for PWM output as I suspected.. Did you choose which pins to use for which purpose or are you using a motor shield which requires certain pins to be used ?
It may still be possible to use pins 9 and 10 but that would require the servo object to be detached before using them and attached again afterwards which sounds very messy. You could do yourself a favour and put the analogWrite() commands in a function along with the servo detach and subsequent servo attach then call the function when required.
On the whole, using other pins would be the best solution although there is an alternative servo library (ServoTimer2) that allows PWM on pins 9 and 10