ArdEV3
Use EV3 peripherals from Arduino microcontrollers.
Loading...
Searching...
No Matches
ev3::Motor Class Reference

#include <EV3Motor.h>

Inheritance diagram for ev3::Motor:
ev3::_::Peripheral< MotorPortConfig >

Public Member Functions

void SetPower (uint8_t power)
 Set the power of the motor. This writes a PWM signal to the enable pin.
void SetDirection (MotorDirection direction)
 Set the direction of the motor. This writes digital signals to the input 1 and 2 pins.
void StartEncoder ()
 Start tracking the encoder position.
void StopEncoder ()
 Stop tracking the encoder position.
void ResetEncoder ()
 Reset the encoder to zero.
void RunToPosition (uint8_t power, unsigned long position)
 Set the motor running to the specified position at the specified power. This will complete asynchronously. In most cases, you will want to call ResetEncoder() first.
virtual void Setup ()
 Initialize the motor. Call this in your global setup function.
virtual void Loop ()
 Run once per cycle – call this in your global loop function.
Public Member Functions inherited from ev3::_::Peripheral< MotorPortConfig >
 Peripheral (MotorPortConfig ports)
 Initialize this peripheral from the specified port configuration.
auto Ports () -> MotorPortConfig const &
 Get the port configuration for this peripheral.

Additional Inherited Members

Protected Attributes inherited from ev3::_::Peripheral< MotorPortConfig >
MotorPortConfig ports

Detailed Description

A class to drive an EV3 motor. See MotorPortConfig for wiring details.

There are a few boilerplate steps that should be followed:

  1. If using the encoder, the motor should be initialized at a global scope.
  2. If using the encoder, call ev3Motor_EncoderGlobal(motor) at a global scope to set up a wrapper function to read the encoder. See encoder-hacks for technical details on why this is necessary.
  3. Call Motor::Setup() in your global setup function to initialize the ports for the motor.
  4. If using the encoder, call ev3Motor_SetupEncoder(motor) after Motor::Setup(). Again, see encoder-hacks.
  5. Call Motor::Loop() in your global loop function.
Examples
motor.cpp, and touchSensor.cpp.

Member Function Documentation

◆ Loop()

void Motor::Loop ( )
virtual

Run once per cycle – call this in your global loop function.

Reimplemented from ev3::_::Peripheral< MotorPortConfig >.

◆ Setup()

void Motor::Setup ( )
virtual

Initialize the motor. Call this in your global setup function.

Reimplemented from ev3::_::Peripheral< MotorPortConfig >.


The documentation for this class was generated from the following files: