ArdEV3
Use EV3 peripherals from Arduino microcontrollers.
Loading...
Searching...
No Matches
motor.cpp

This sketch demonstrates usage of the Motor class to drive a motor.

#include <Arduino.h>
#include <EV3Motor.h>
#define ENB 6
#define IN3 5
#define IN4 4
#define ENCA 2
#define ENCB 13
#define BUTTON 8
ev3::Motor motor(ev3::MotorPortConfig{.Enable = ENB, .In1 = IN3, .In2 = IN4, .EncoderA = ENCA, .EncoderB = ENCB});
ev3Motor_EncoderGlobal(motor);
void setup() {
Serial.begin(9600);
pinMode(BUTTON, INPUT_PULLUP);
motor.Setup();
ev3Motor_SetupEncoder(motor);
motor.SetDirection(ev3::MotorDirection::FORWARD);
}
int previousButtonValue = HIGH;
void loop() {
// put your main code here, to run repeatedly:
int buttonValue = digitalRead(BUTTON);
if (!buttonValue && previousButtonValue)
{
motor.ResetEncoder();
motor.RunToPosition(255, 3000);
}
motor.Loop();
previousButtonValue = buttonValue;
}
Definition EV3Motor.h:60
Definition EV3Motor.h:42