AmebaServo Class

AmebaServo Class

Description
A class used for controlling servo motors connected to Ameba boards.

Syntax
class AmebaServo

Members

Public Constructors 
AmebaServo::AmebaServoConstructs an AmebaServo object.
Public Methods 
AmebaServo::attachAttach a PWM pin to control servo.
AmebaServo::detachDetach the servo.
AmebaServo::writeWrite a value to control servo. The value is between 0 -180 degrees.
AmebaServo::writeMicrosecondsWrite a value to control servo. The value is between 544 – 2400ms.
AmebaServo::readRead the value from servo and returns current pulse width as an angle between 0 and 180 degrees.
AmebaServo::readMicrosecondsRead the value from servo and returns current pulse width in microseconds.
AmebaServo::attachedCheck if the servo is attached.

AmebaServo::attach

Description
Attach a PWM pin to control servo on Ameba boards. Minimum and maximum pulse width can be set optionally. By default, the minimum and maximum pulse width are 544ms and 2400ms respectively. The function returns 0 when the execution is completed.

Syntax
uint8_t attach(int pin);
uint8_t attach(int pin, int min, int max);

Parameters
pin: A PWM pin that is one of the Ameba boards’ PWM pins.
min: Minimum pulse width to be set for PWM. By default, the min is 544ms.
max: Maximum pulse width to be set for PWM. By default, the max is 2400ms.

Returns
NA

Example Code
Example: ServoSweep
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/Analog/examples/ServoSweep/ServoSweep.ino)
The code demonstrates a servo motor sweeping from 0 – 180 – 0 degrees, in 1-degree intervals.

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

AmebaServo::detach

Description
Detach the servo by disable the PWM pin set in attach().

Syntax
void detach(void);

Parameters
NA

Returns
NA

Example Code
NA

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

AmebaServo::write

Description
Write an integer value to control servo. The value is between 0 -180 degrees.

Syntax
void write(int value);

Parameters
value: An integer value that should be between 0 -180. If the value is < 0, it will be taken as 0 and if the value >180, it will be taken as 180.

Returns
NA

Example Code
Example: ServoSweep
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/Analog/examples/ServoSweep/ServoSweep.ino)

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

AmebaServo::writeMicroseconds

Description
Write a value to control servo. The value is between 544 – 2400ms that represents pulse width.

Syntax
void writeMicroseconds(int value);

Parameters
value: An integer value that should be between 544 – 2400ms as pulse width. If the value is < 544ms, it will be taken as 544ms and if the value > 2400ms, it will be taken as 2400ms.

Returns
NA

Example Code
NA

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

AmebaServo::read

Description
The function reads the value from servo and returns current pulse width as an angle between 0 – 180 degrees.

Syntax
int read(void);

Parameters
NA

Returns
This function returns integer value that represents pulse width between 0 – 180 degrees.

Example Code
NA

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

AmebaServo::readMicroseconds

Description
The function reads and returns the pulse width of the current servo in microseconds.

Syntax
int readMicroseconds(void);

Parameters
NA

Returns
This function returns integer value that represents pulse width in microseconds.

Example Code
NA

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

AmebaServo::attached

Description
Check if the servo PWM pin is attached successfully.

Syntax
bool attached(void);

Parameters
NA

Returns
This function returns 1 if the servo has been attached, else it returns 0.

Example Code
Example: ServoSweep
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/Analog/examples/ServoSweep/ServoSweep.ino)

Notes and Warnings
“AmebaServo.h” must be included to use the class function.

請先確認已安裝QQ通訊軟體