ServoOut
A source unit that controls a standard servo-motor.
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board. Note that servos draw considerable power, so if you need to drive more than one or two, you’ll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together.
Example
Sweeps the shaft of a servo motor back and forth across 180 degrees.
#include <Plaquette.h>
#include <PqServo.h>
// The servo-motor output on pin 9.
ServoOut servo(9);
// Oscillator to make the servo sweep.
Wave oscillator(SINE, 2.0);
void begin() {
// Position the servo in center.
servo.center();
}
void step() {
// Updates the value and send it back as output.
oscillator >> servo;
}
-
class ServoOut : public AbstractServoOut
Standard servo-motor (angular).
Public Functions
-
ServoOut(uint8_t pin, Engine &engine = Engine::primary())
Constructor for a standard servo-motor.
- Parameters
pin – the pin number
-
virtual float putAngle(float angle)
Sets the servomotor position to a specific angle between 0 and 180 degrees.
- Parameters
angle – the angle in degrees
- Returns
the current angle
-
virtual float getAngle()
Return the current angular angle in [0, 180].
-
inline virtual void center()
Re-centers the servo-motor.
-
virtual float put(float value)
Pushes value into the unit.
- Parameters
value – the value sent to the unit
- Returns
the new value of the unit
-
inline uint8_t pin() const
Returns the pin this servomotor is attached to.
-
inline virtual void activate()
Activates the servomotor (default).
-
inline virtual void deactivate()
Deactivates the servomotor.
-
inline virtual bool isActive()
Returns true if the servomotor is active.
-
inline virtual float get()
Returns value in [0, 1].
-
inline virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
-
inline float seconds() const
Returns engine time in seconds.
-
inline uint32_t milliSeconds() const
Returns engine time in milliseconds.
-
inline uint64_t microSeconds() const
Returns engine time in microseconds.
-
inline unsigned long nSteps() const
Returns number of engine steps.
-
inline float sampleRate() const
Returns engine sample rate.
-
inline float samplePeriod() const
Returns enginesample period.
-
inline operator float()
Object can be used directly to access its value.
-
inline explicit operator bool()
Operator that allows usage in conditional expressions.
-
ServoOut(uint8_t pin, Engine &engine = Engine::primary())