This example is a variation of the Motor example that uses a TouchSensor as the button to trigger it.
#include <Arduino.h>
#include <ArdEV3.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);
button.Setup();
motor.Setup();
ev3Motor_SetupEncoder(motor);
motor.SetDirection(ev3::MotorDirection::FORWARD);
}
bool previousPressed = false;
void loop() {
bool pressed = button.Pressed();
if (pressed && !previousPressed)
{
Serial.println("Running");
motor.ResetEncoder();
motor.RunToPosition(255, 3000);
}
motor.Loop();
previousPressed = pressed;
}
Definition EV3TouchSensor.h:22
Definition EV3TouchSensor.h:15