Class Motor

Class Documentation

class Motor

This class allows to control a DC motor by enabling it and setting its speed. The involved pins are expected to be connected to a full-bridge motor driver module, such as the L298N.

Public Functions

inline Motor(const DigitalOut *enable_digital_out, const PwmOut *forward_pwm_out, const PwmOut *backward_pwm_out)

Constructs a new Motor object.

Parameters:
  • enable_digital_out – Digital output connected to motor enable pin.

  • forward_pwm_out – PWM output connected to motor forward pin.

  • backward_pwm_out – PWM output connected to motor backward pin.

void begin()

Initializes the motor.

void enable(bool enabled)

Enables the motor.

Parameters:

enabled – True to enable the motor, false otherwise.

void set_speed(int speed)

Sets the motor speed.

Parameters:

speedMotor speed value.