STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
Servo Class Reference

Servo motor controller. More...

#include <Servo.h>

Public Member Functions

 Servo ()
 Create a servo instance and assign it a channel index.
 
uint8_t attach (pin_size_t pin, int value=DEFAULT_PULSE_WIDTH)
 Attach the servo to a pin, using the default min and max pulse widths.
 
uint8_t attach (pin_size_t pin, int min, int max, int value=DEFAULT_PULSE_WIDTH)
 Attach the servo to a pin, with custom min and max pulse widths.
 
void detach ()
 Stop the servo from pulsing its pin.
 
void write (int value)
 Set the servo position.
 
void writeMicroseconds (int value)
 Set the servo pulse width.
 
int read ()
 Get the last written position.
 
int readMicroseconds ()
 Get the last written pulse width.
 
bool attached ()
 Check if the servo is attached.
 

Detailed Description

Servo motor controller.

Each instance drives one servo on a pin, using a shared 16 bit timer.

Constructor & Destructor Documentation

◆ Servo()

Servo::Servo ( )

Create a servo instance and assign it a channel index.

Note
If no channel is left (MAX_SERVOS reached), the instance is invalid: its index is INVALID_SERVO.

Member Function Documentation

◆ attach() [1/2]

uint8_t Servo::attach ( pin_size_t  pin,
int  min,
int  max,
int  value = DEFAULT_PULSE_WIDTH 
)

Attach the servo to a pin, with custom min and max pulse widths.

The pin is set as output and the servo is moved to the initial value. The min and max values are used to limit the writes and have a resolution of 4 microseconds.

Parameters
pinPin number to attach the servo to.
minPulse width in microseconds for 0 degrees (MIN_PULSE_WIDTH by default with the 2 parameters version).
maxPulse width in microseconds for 180 degrees (MAX_PULSE_WIDTH by default with the 2 parameters version).
valueInitial value, as an angle in degrees or a pulse width in microseconds. Default: DEFAULT_PULSE_WIDTH.
Returns
Index of the channel used, or INVALID_SERVO if no channel is available.

◆ attach() [2/2]

uint8_t Servo::attach ( pin_size_t  pin,
int  value = DEFAULT_PULSE_WIDTH 
)

Attach the servo to a pin, using the default min and max pulse widths.

The pin is set as output and the servo is moved to the initial value.

Parameters
pinPin number to attach the servo to.
valueInitial value, as an angle in degrees or a pulse width in microseconds. Default: DEFAULT_PULSE_WIDTH.
Returns
Index of the channel used, or INVALID_SERVO if no channel is available.

◆ attached()

bool Servo::attached ( )

Check if the servo is attached.

Returns
true if the servo is attached, false otherwise.

◆ detach()

void Servo::detach ( )

Stop the servo from pulsing its pin.

The timer is paused when no servo is active.

◆ read()

int Servo::read ( )

Get the last written position.

Returns
Current position as an angle between 0 and 180 degrees.

◆ readMicroseconds()

int Servo::readMicroseconds ( )

Get the last written pulse width.

Returns
Current pulse width in microseconds, 0 if the servo instance is invalid.

◆ write()

void Servo::write ( int  value)

Set the servo position.

A value less than MIN_PULSE_WIDTH is treated as an angle (limited to 0-180), otherwise it is treated as a pulse width in microseconds (see writeMicroseconds()).

Parameters
valueAngle in degrees (0 to 180) or pulse width in microseconds.

◆ writeMicroseconds()

void Servo::writeMicroseconds ( int  value)

Set the servo pulse width.

The value is clamped to the min and max pulse widths of this servo.

Parameters
valuePulse width in microseconds.

The documentation for this class was generated from the following files: