Skip to content

Commit e8e1d37

Browse files
committed
Remove pad tracking. Increase map to include 180.
1 parent 75d12a8 commit e8e1d37

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

libraries/Servo/src/Servo.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Servo::Servo()
3434
void Servo::attach(uint8_t pinNumber)
3535
{
3636
_servoPinNumber = pinNumber;
37-
_servoPadNumber = ap3_gpio_pin2pad(pinNumber);
37+
pinMode(_servoPinNumber, OUTPUT);
3838
}
3939

4040
void Servo::write(uint8_t servoPosition)
@@ -43,9 +43,9 @@ void Servo::write(uint8_t servoPosition)
4343
if (_servoPosition > 180)
4444
_servoPosition = 180; //Bounds check
4545

46-
uint16_t newServoPosition = map(servoPosition, 0, 180, 0, 1023);
46+
uint16_t newServoPosition = map(servoPosition, 0, 181, 0, ((uint16_t)0x01 << getServoResolution()));
4747

48-
servoWrite(_servoPadNumber, newServoPosition); // This and the above write should both produce 1.5 ms wide pulses, though using different resolutions
48+
servoWrite(_servoPinNumber, newServoPosition); // This and the above write should both produce 1.5 ms wide pulses, though using different resolutions
4949
}
5050

5151
// void Servo::writeMicroseconds(uint8_t servoPosition)
@@ -55,9 +55,9 @@ void Servo::write(uint8_t servoPosition)
5555

5656
void Servo::detach(void)
5757
{
58-
_servoPinNumber = NULL;
59-
_servoPadNumber = NULL;
6058
pinMode(_servoPinNumber, INPUT); //Will stop PWM output
59+
60+
_servoPinNumber = 0;
6161
}
6262

6363
uint8_t Servo::read(void)

libraries/Servo/src/Servo.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class Servo
3838
bool attached(uint8_t pinNumber);
3939

4040
private:
41-
uint8_t _servoPadNumber = NULL;
42-
uint8_t _servoPinNumber = NULL;
41+
uint8_t _servoPinNumber = 0;
4342
uint8_t _servoPosition;
4443
};
4544

0 commit comments

Comments
 (0)