ContinuousServoOut

A source unit that controls a continuous rotation servo-motor. A continuous servo-motor can move indefinitely forward or backwards.

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

Every time a button is pushed, the motor is stopped. Then upon button release it starts moving in the opposite direction.

#include <Plaquette.h>
#include <PqServo.h>

// The servo-motor output on pin 9.
ContinuousServoOut servo(9);

// The push-button.
DigitalIn button(2);

// Preserves the servo last speed value.
float lastValue = 0;

void begin() {
  // Debounce button.
  button.debounce();
  // Starts the servo.
  servo.put(1.0);
}

void step() {
  if (button) {
    // Save speed.
    lastValue = servo.get();
    // Stop servo.
    servo.stop();
  }
  else if (button.fell()) {
    // Reset speed.
    servo.put(lastValue);
    // ... then invert it.
    servo.reverse();
  }
}
class ContinuousServoOut : public AbstractServoOut

Continuous servo-motor.

Public Functions

ContinuousServoOut(uint8_t pin = 9)

Constructor for a continuous rotation servo-motor.

Parameters:

pin – the pin number

virtual void stop()

Stops the servo-motor.

virtual void reverse()

Sends servo-motor in reverse mode.

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 float get()

Returns value in [0, 1].

See Also