I have been studying arduino coding for a few days now and found a website that talked about millis and servos. I'm basically delving into lots of different codes, pulling them apart and seeing how they work etc.
I used one part of the code to move a servo and took away all the rest of the code and found one part very interesting.
The code that I am looking at is>>> #include <Servo.h>
class Sweeper
{
Servo servo; // the servo
int pos; // current servo position
int increment; // increment to move for each interval
int updateInterval; // interval between updates
unsigned long lastUpdate; // last update of position
The part of the code I wanted to find out about is...
void Detach()
{
servo.attach(pin);
}
The code still moves the servo when this bit of code is removed, so I just wanted to find out why it is there.
I'm thinking it may be part of a loop that has to detach then re-attach in order for the code to work.
Cheers,
Chris.
detach() is a just standard function of the Servo.h library. It's not used very often in normal servo coding.
Why whoever wrote the Sweeper class chose to include a public method to call it is anyone's guess. Perhaps just for completeness or they thought they might need it one day.
slipstick:
detach() is a just standard function of the Servo.h library. It's not used very often in normal servo coding.
Why whoever wrote the Sweeper class chose to include a public method to call it is anyone's guess. Perhaps just for completeness or they thought they might need it one day.
Steve
Cheers steve, thanks for the great explanation and it was very helpful for my learning.
Have a great new year.
Chris.