From 1e91fd303763f731cb82b7a035e61f98472ed62c Mon Sep 17 00:00:00 2001 From: nkaaf Date: Mon, 14 Feb 2022 13:46:24 +0100 Subject: [PATCH 1/2] update description of write method --- src/Servo.h | 2 +- src/avr/Servo.cpp | 2 +- src/mbed/Servo.cpp | 1 - src/megaavr/Servo.cpp | 1 - src/sam/Servo.cpp | 1 - src/samd/Servo.cpp | 1 - 6 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Servo.h b/src/Servo.h index 53ecb8e..43a6f38 100644 --- a/src/Servo.h +++ b/src/Servo.h @@ -108,7 +108,7 @@ class Servo uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or INVALID_SERVO if failure uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. void detach(); - void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds + void write(int value); // if value is < 544 and desired arch is not nrf52, its treated as an angle, otherwise as pulse width in microseconds void writeMicroseconds(int value); // Write pulse width in microseconds int read(); // returns current pulse width as an angle between 0 and 180 degrees int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) diff --git a/src/avr/Servo.cpp b/src/avr/Servo.cpp index 11fecc5..5f2266b 100644 --- a/src/avr/Servo.cpp +++ b/src/avr/Servo.cpp @@ -264,7 +264,7 @@ void Servo::detach() 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()); diff --git a/src/mbed/Servo.cpp b/src/mbed/Servo.cpp index efb67f9..c29db2e 100644 --- a/src/mbed/Servo.cpp +++ b/src/mbed/Servo.cpp @@ -83,7 +83,6 @@ void Servo::detach() void Servo::write(int value) { - // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) if (value < MIN_PULSE_WIDTH) { if (value < 0) diff --git a/src/megaavr/Servo.cpp b/src/megaavr/Servo.cpp index 59b3e44..d24702f 100644 --- a/src/megaavr/Servo.cpp +++ b/src/megaavr/Servo.cpp @@ -160,7 +160,6 @@ void Servo::detach() void Servo::write(int value) { - // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) if (value < MIN_PULSE_WIDTH) { if (value < 0) diff --git a/src/sam/Servo.cpp b/src/sam/Servo.cpp index df5058f..34f5b10 100644 --- a/src/sam/Servo.cpp +++ b/src/sam/Servo.cpp @@ -228,7 +228,6 @@ void Servo::detach() void Servo::write(int value) { - // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) if (value < MIN_PULSE_WIDTH) { if (value < 0) diff --git a/src/samd/Servo.cpp b/src/samd/Servo.cpp index d8e2ec4..99193f4 100644 --- a/src/samd/Servo.cpp +++ b/src/samd/Servo.cpp @@ -243,7 +243,6 @@ void Servo::detach() void Servo::write(int value) { - // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) if (value < MIN_PULSE_WIDTH) { if (value < 0) From 8927e0093a7587aa1ffe5d2ed792a7e5f113622f Mon Sep 17 00:00:00 2001 From: nkaaf Date: Mon, 14 Feb 2022 13:56:12 +0100 Subject: [PATCH 2/2] clarify 0 and 180 as limit --- src/Servo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Servo.h b/src/Servo.h index 43a6f38..ef09c80 100644 --- a/src/Servo.h +++ b/src/Servo.h @@ -108,7 +108,7 @@ class Servo uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or INVALID_SERVO if failure uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. void detach(); - void write(int value); // if value is < 544 and desired arch is not nrf52, its treated as an angle, otherwise as pulse width in microseconds + void write(int value); // if value is < 544 and desired arch is not nrf52, its treated as an angle between 0 and 180, where values higher than 180 are set to 180 and values less than 0 are set to 0; otherwise as pulse width in microseconds void writeMicroseconds(int value); // Write pulse width in microseconds int read(); // returns current pulse width as an angle between 0 and 180 degrees int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release)