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
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() {
int buttonValue = digitalRead(BUTTON);
if (!buttonValue && previousButtonValue)
{
motor.ResetEncoder();
motor.RunToPosition(255, 3000);
}
motor.Loop();
previousButtonValue = buttonValue;
}