Skip to content

Commit fa169b1

Browse files
author
Nathan Seidle
committed
Add writeMicroseconds() and a few keywords.
1 parent 55de173 commit fa169b1

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

cores/arduino/ard_sup/ap3_gpio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_INPUT_PULLDOWN;
4545
#define AP3_GPIO_IS_VALID(pad) ((pad >= 0) && (pad < AP3_GPIO_MAX_PADS))
4646

4747
extern ap3_gpio_pad_t ap3_gpio_pin2pad(ap3_gpio_pin_t pin);
48-
#define AP3_GPIO_PAD_UNUSED (-1)
48+
#define AP3_GPIO_PAD_UNUSED (255)
4949

5050
#define AP3_GPIO_DEFAULT_PINCFG AP3_GPIO_PINCFG_NULL
5151

libraries/Servo/keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ read KEYWORD2
1717

1818
writeMicroseconds KEYWORD2
1919
attached KEYWORD2
20+
servoWriteResolution KEYWORD2
21+
getServoResolution KEYWORD2
2022

2123
#######################################
2224
# Instances (KEYWORD2)

libraries/Servo/src/Servo.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ SOFTWARE.
2828
//Constructor
2929
Servo::Servo()
3030
{
31-
3231
}
3332

3433
void Servo::attach(uint8_t pinNumber, uint16_t minMicros, uint16_t maxMicros)
@@ -51,15 +50,22 @@ void Servo::write(uint8_t servoPosition)
5150
_servoPosition = 180; //Bounds check
5251

5352
uint16_t newServoPosition = map(servoPosition, 0, 181, 0, ((uint16_t)0x01 << getServoResolution()));
54-
5553
servoWrite(_servoPinNumber, newServoPosition, _minMicros, _maxMicros);
5654
}
5755

5856
void Servo::writeMicroseconds(uint16_t microSecs)
5957
{
60-
//Convert microseconds to PWM value
61-
uint16_t newServoPosition = microSecs;
62-
servoWrite(_servoPinNumber, newServoPosition, _minMicros, _maxMicros);
58+
uint16_t extendedMin = _minMicros;
59+
uint16_t extendedMax = _maxMicros;
60+
61+
if (microSecs > _maxMicros)
62+
extendedMax = microSecs;
63+
if (microSecs < _minMicros)
64+
extendedMin = microSecs;
65+
66+
//Map microseconds to PWM value
67+
uint16_t newServoPosition = map(microSecs, extendedMin, extendedMax + 1, 0, ((uint16_t)0x01 << getServoResolution()));
68+
servoWrite(_servoPinNumber, newServoPosition, extendedMin, extendedMax);
6369
}
6470

6571
void Servo::detach(void)

0 commit comments

Comments
 (0)