![]() |
Serial Wombat Arduino Library
|
A class to control Servos attached to the Serial Wombat. More...
#include <SerialWombatServo.h>
Public Member Functions | |
SerialWombatServo (SerialWombat &sw) | |
Constructor for the SerialWombatServo Class. More... | |
~SerialWombatServo () | |
void | attach (uint8_t pin) |
Initialize a servo on the specified pin. More... | |
void | attach (uint8_t pin, bool reverse) |
Initialize a servo on the specified pin. More... | |
void | attach (uint8_t pin, uint16_t min, uint16_t max) |
Initialize a servo on the specified pin. More... | |
void | attach (uint8_t pin, uint16_t min, uint16_t max, bool reverse) |
Initialize a servo on the specified pin. More... | |
void | write (uint8_t angle) |
Writes a value to the servo. More... | |
void | write16bit (uint16_t position) |
Writes a 16 bit value to the servo. More... | |
uint8_t | read (void) |
returns the last position of the servo scaled to a number from 0 to 180. More... | |
A class to control Servos attached to the Serial Wombat.
The SerialWombatServo class is used to control hobby servos attached to the Serial Wombat.
Any output-capable pin may be attached to an instance of the SerialWombatServo class. A separate instance should be declared for each Servo.
The SW4B_Ard_Servo example included with the Arduino library shows how to use this class.
This class uses "attach" rather than "begin" to initialize servos to be consistent with the Arduino Servo native API.
A Tutorial video is also avaialble:
SerialWombatServo::SerialWombatServo | ( | SerialWombat & | sw | ) |
Constructor for the SerialWombatServo Class.
sw | A reference to a previously declared SerialWombat to which the Servo is connected. |
SerialWombatServo::~SerialWombatServo | ( | ) |
void SerialWombatServo::attach | ( | uint8_t | pin | ) |
Initialize a servo on the specified pin.
This function must be called after the SerialWombat instance specified in the constructor has been initialized with a begin call.
This function initializes a servo with a minimum pulse of 544 uS and a maximum pulse of 2400uS to be consistent with the native Arduino API attach function.
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
void SerialWombatServo::attach | ( | uint8_t | pin, |
bool | reverse | ||
) |
Initialize a servo on the specified pin.
This function must be called after the SerialWombat instance specified in the constructor has been initialized with a begin call.
This function initializes a servo with a minimum pulse of 544 uS and a maximum pulse of 2400uS to be consistent with the native Arduino API attach function.
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
reverse | If true, the pulse widths will be reversed, with the longest pulse width corresponding to 0 position. |
void SerialWombatServo::attach | ( | uint8_t | pin, |
uint16_t | min, | ||
uint16_t | max | ||
) |
Initialize a servo on the specified pin.
This function must be called after the SerialWombat instance specified in the constructor has been initialized with a begin call.
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
min | Minimum pulse width in uS. Minimum functional value is 100. |
max | Maximum pulse width in uS |
void SerialWombatServo::attach | ( | uint8_t | pin, |
uint16_t | min, | ||
uint16_t | max, | ||
bool | reverse | ||
) |
Initialize a servo on the specified pin.
This function must be called after the SerialWombat instance specified in the constructor has been initialized with a begin call.
pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 |
min | Minimum pulse width in uS. Minimum functional value is 100. |
max | Maximum pulse width in uS |
reverse | If true, the pulse widths will be reversed, with the longest pulse width corresponding to 0 position. |
uint8_t SerialWombatServo::read | ( | void | ) |
returns the last position of the servo scaled to a number from 0 to 180.
void SerialWombatServo::write | ( | uint8_t | angle | ) |
Writes a value to the servo.
This funciton allows setting the "angle" of a servo, although actual travel may vary. Consider using the Serial Wombat function write16bit for higher resolution
angle | A value from 0 to 180 |
void SerialWombatServo::write16bit | ( | uint16_t | position | ) |
Writes a 16 bit value to the servo.
This funciton scales the pulse width of the signal being sent to the servo.
position | Servo position. 0 sends the minimum pulse width. 65535 sends the maximum pulse width (unless Reverse is enabled) |