Quick look in the lib:
Servo::write1) negative values make no sense , replace by unsigned int types ?
2) I don't like it that the param value in write() can have two distinct meanings.
void Servo::write(int value) <<<<<<<<< make this unsigned int ??
{
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; <<<<<<<<<<<<<< that line not needed if value is unsigned int
if(value > 180) value = 180;
value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
}
this->writeMicroseconds(value);
}
==>
// only supports angles between 0..180
// use writeMicroseconds for pwm
void Servo::write(uint8_t value)
{
if(value > 180) value = 180;
this->writeMicroseconds(map(value, 0, 180, SERVO_MIN(), SERVO_MAX()));
}
Servo::writeMicroseconds1) negative value make no sense , replace by unsigned int?
void Servo::writeMicroseconds(int value)
==>
void Servo::writeMicroseconds(unsigned int value)[/code
[b]Servo::attach[/b]
1) negative value make no sense , replace by unsigned int?
2) test MIN_PULSE_WIDTH <= min <= max <= MAX_PULSE_WIDTH?
uint8_t Servo::attach(int pin, int min, int max)
==>
uint8_t Servo::attach(uint8_t pin, unsigned int min, unsigned int max)
Servo::read1) strange values if ( this->servoIndex == INVALID_SERVO ); readMicroseconds returns value 0 << SERVO_MIN.
int Servo::read() // return the value as degrees
{
return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
}
==>
int Servo::read() // return the value as degrees && -1 if invalid.
{
if ( this->servoIndex != INVALID_SERVO )
return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
return -1;
}
Servo::readMicroseconds1) return type of function differs from internal var pulsewidth; which is stricly speaking not needed
2) using -1 for invalid values..
int Servo::readMicroseconds()
{
unsigned int pulsewidth;
if( this->servoIndex != INVALID_SERVO )
pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009
else
pulsewidth = 0; //
return pulsewidth;
}
==>
int Servo::readMicroseconds()
{
if( this->servoIndex != INVALID_SERVO )
return ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009
return -1;
}
my 2 cents
Rob