Serial Wombat Arduino Library
Public Member Functions | List of all members
SerialWombatServo Class Reference

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...
 

Detailed Description

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:

https://youtu.be/WiciAtS1ng0

Constructor & Destructor Documentation

◆ SerialWombatServo()

SerialWombatServo::SerialWombatServo ( SerialWombat sw)

Constructor for the SerialWombatServo Class.

Parameters
swA reference to a previously declared SerialWombat to which the Servo is connected.

◆ ~SerialWombatServo()

SerialWombatServo::~SerialWombatServo ( )

Member Function Documentation

◆ attach() [1/4]

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.

Parameters
pinThe Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3

◆ attach() [2/4]

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.

Parameters
pinThe Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3
reverseIf true, the pulse widths will be reversed, with the longest pulse width corresponding to 0 position.

◆ attach() [3/4]

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.

Parameters
pinThe Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3
minMinimum pulse width in uS. Minimum functional value is 100.
maxMaximum pulse width in uS

◆ attach() [4/4]

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.

Parameters
pinThe Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3
minMinimum pulse width in uS. Minimum functional value is 100.
maxMaximum pulse width in uS
reverseIf true, the pulse widths will be reversed, with the longest pulse width corresponding to 0 position.

◆ read()

uint8_t SerialWombatServo::read ( void  )

returns the last position of the servo scaled to a number from 0 to 180.

Returns
A position value from 0 to 180.

◆ write()

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

Parameters
angleA value from 0 to 180

◆ write16bit()

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.

Parameters
positionServo position. 0 sends the minimum pulse width. 65535 sends the maximum pulse width (unless Reverse is enabled)