Skip to content

Servo.attach() call to Servo::write() before min/max are configured leads to issue when writting angles in degrees #2308

Closed
@jan019

Description

@jan019

Describe the bug
The Servo library calls the write() function within the attach() function

before configuring this->min and this->max values
this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
this->max = (MAX_PULSE_WIDTH - max) / 4;
, which however need to be configured for write() function to work correctly when the servo position is set in degrees. The function write() uses the this->min and this->max values to map the passed value in degrees between min and max https://github.com/stm32duino/Arduino_Core_STM32/blob/641f3d8883e9a7220f65dded355dc32e218a990d/libraries/Servo/src/stm32/Servo.cpp#L156/

To Reproduce

int min = 40;
int max = 70;
int value = 40;

// on first call to attach, the write is called with a different value in this->min and this->max than on following calls
Servo.attach(pin, min, max, value)
  • STM32 core version: 2.7.1

The write() function should either not be called in the attach() function at all, or it must be called after this->min and this->max are configured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy