Apply LIMIT macro

This commit is contained in:
Scott Lahteine
2019-07-10 03:33:28 -05:00
parent 9817976375
commit ed0e6afacb
14 changed files with 31 additions and 34 deletions

View File

@ -48,8 +48,8 @@ void Servo::detach() { ledcDetachPin(this->pin); }
int Servo::read() { return this->degrees; }
void Servo::write(int degrees) {
this->degrees = constrain(degrees, MIN_ANGLE, MAX_ANGLE);
void Servo::write(int inDegrees) {
this->degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE);
int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE);
ledcWrite(channel, duty);

View File

@ -127,7 +127,7 @@ void Servo::writeMicroseconds(int value) {
byte channel = this->servoIndex;
if (channel < MAX_SERVOS) { // ensure channel is valid
// ensure pulse width is valid
value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
LIMIT(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION);
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
CRITICAL_SECTION_START;