Skip to content

write() on Arduino Uno Rev4 Wifi only works with angle #133

Open
@thomashargrove

Description

@thomashargrove

The Servo.h header file has this comment for write():

// if value is < 200 it's treated as an angle, otherwise as pulse width in microseconds

This is true for AVR boards:

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);
}

But the Uno Rev4 implementation seems to only work with angles:

void Servo::write(int angle)
{
    if (servoIndex != SERVO_INVALID_INDEX) {
        ra_servo_t *servo = &ra_servos[servoIndex];
        angle = constrain(angle, 0, 180);
        writeMicroseconds(map(angle, 0, 180, servo->period_min, servo->period_max));
    }
}

From a quick scan of the different implementations:

  1. Avr, mbed, megaavr, sam, samd, xmc - Supports angles and microseconds
  2. nrf52, renesas, stm32f4 - Only works with angles

Should be an easy fix, happy to send a PR if someone will approve it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions