Basic question about Servo.h library

Hello,

I have a question concerning the code of Servo.h and Servo.cpp that is included in Arduino.

Basically I have examined the code - as it gives me the possibility to understand C++ better.

But I have one problem:

- I cannot find how the pin is set high in Servo.h and Servo.cpp - just like the digitalWrite function from Arduino.

I ve posted the code with the specific function:

void Servo::write(int value)
{
if(value < MIN_PULSE_WIDTH)
{ // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
if(value < 0) value = 0;
if(value > 180) value = 180;
value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
}
this->writeMicroseconds(value);
}

void Servo::writeMicroseconds(int value)
{
// calculate and store the values for the given channel
byte channel = this->servoIndex;
if( (channel < MAX_SERVOS) ) // ensure channel is valid
{
if( value < SERVO_MIN() ) // ensure pulse width is valid
value = SERVO_MIN();
else if( value > SERVO_MAX() )
value = SERVO_MAX();

value = value - TRIM_DURATION;
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009

uint8_t oldSREG = SREG;
cli();
servos[channel].ticks = value;
SREG = oldSREG;
}

But I cannot find anywhere a command to set pin high (for the duration int value that is called with the function ).

Would appreciate help very much :).

Look at the handler that is triggered by the hardware timer

Thanks a lot. Now I can further approach on understanding the code.

But I must say that it is still tricky to understand :/, even after one year.

BigDee2:
Thanks a lot. Now I can further approach on understanding the code.
But I must say that it is still tricky to understand :/, even after one year.

The code basically maintains the list of servos you have instantiated and uses a timer that is set to come back regularly to do what’s necessary to maintain the right pwm for each servo, turning the pins on or off

Keep practicing and reading code, that’s a good way to learn !