arduino-libraries / Servo

Servo Library for Arduino
http://arduino.cc/
GNU Lesser General Public License v2.1
233 stars 251 forks source link

Attach with Min Max bug #103

Open Teehee2 opened 1 year ago

Teehee2 commented 1 year ago

There seems to be an issue witihin the library for values of min and max in the attach(pin, min, max) function. I am using an official Arduino Uno R3 and IDE version 1.8.19, Servo library version 1.1.8. I am reading values back using the readMicrosecond function through Serial.

When using the overloaded attach function, min values above 1059 and max values below about 1900 do not work. Instead the library acts as no limits, my serial prints even reach up to 2800 microseconds. Please see details below:

Smallest microsecond range (works perfectly):

int min = 1059;
  int max = 1900;
  Servo2.write(0);
  Serial.println(Servo2.attach(servo2Pin, min, max));
  tftText("Servo 2");

'Unlimited' range after higher min:

int min = 1060
  int max = 1900;
  Servo2.write(0);
  Serial.println(Servo2.attach(servo2Pin, min, max));
  tftText("Servo 2");

'Unlimited' range after higher max:

int min = 1060
  int max = 1850;
  Servo2.write(0);
  Serial.println(Servo2.attach(servo2Pin, min, max));
  tftText("Servo 2");

Higher range reaches up to about 2865: image

Edit 23:40 18/07/2022: Wrong value for max, fixed now.

Teehee2 commented 1 year ago

Just saw #101 , seems to provide a fix. Thanks guys!

Teehee2 commented 1 year ago

After some testing changing from uint8_t to int only slightly allows more flexibility. There still seems to be a problem.