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

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
ev3::Motor motor(ev3::MotorPortConfig{.Enable = ENB, .In1 = IN3, .In2 = IN4, .EncoderA = ENCA, .EncoderB = ENCB});
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() {
// put your main code here, to run repeatedly:
bool pressed = button.Pressed();
if (pressed && !previousPressed)
{
Serial.println("Running");
motor.ResetEncoder();
motor.RunToPosition(255, 3000);
}
motor.Loop();
previousPressed = pressed;
}
Definition EV3Motor.h:60
Definition EV3TouchSensor.h:22
Definition EV3Motor.h:42
Definition EV3TouchSensor.h:15