Example 18 ‐ Stepper angle controlled by joystick - GSTCH/SketchMadeEASY GitHub Wiki

The stepper change the angle in relation to a joystick. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Examples/18-StepperAngleControlledByJoystick".

Adafruit MotorShield V2 at I2C‐Bus

Schematic

Code

#include <Easy.h>

//*****************************************************************
// Parameter Adafruit MotorShield V2 
#define STEPPER_NR 2
#define STEPPER_RPM 20
#define STEPPER_MIN_ANGLE -180
#define STEPPER_MAX_ANGLE 180

// Stepper motor: Moons PG22L71.7
#define STEPPER_RESOLUTION 20
#define STEPPER_GEARRATIO 71

// Parameter JoyStick
#define JOYSTICK_AXIS_PIN A10

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Define Actuators:
  Actuator* stepper = new ServoStepperPositionI2C(STEPPER_NR, STEPPER_RESOLUTION, STEPPER_GEARRATIO, STEPPER_MIN_ANGLE, STEPPER_MAX_ANGLE, STEPPER_RPM);

  //** Define Input
  Input* xAxis = new JoystickAxis(JOYSTICK_AXIS_PIN, false);

  //** Define logic with condition and relation
  Relation* relationServo = new Relation1to1(NULL, stepper, xAxis);
  // ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  // Depending on Arduino it needs a short delay. Do not add any other delays!
  delay(5);
}

MotorShield L9110

Code

#include <Easy.h>

//*****************************************************************
// Parameter Motor Shield like L9110
#define STEPPER_PIN1 9
#define STEPPER_PIN2 10
#define STEPPER_PIN3 11
#define STEPPER_PIN4 12
#define STEPPER_RPM 20
#define STEPPER_MIN_ANGLE -180
#define STEPPER_MAX_ANGLE 180

// Stepper motor:  Moons PG22L71.7
#define STEPPER_RESOLUTION 20
#define STEPPER_GEARRATIO 71

// Parameter JoyStick
#define JOYSTICK_AXIS_PIN A10

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Define Actuators:
  ServoStepperPositionI2C* stepper = new ServoStepperPositionI2C(STEPPER_NR, STEPPER_RESOLUTION, STEPPER_GEARRATIO, STEPPER_MIN_ANGLE, STEPPER_MAX_ANGLE, STEPPER_RPM);

  //** Define Input
  JoystickAxis* xAxis = new JoystickAxis(JOYSTICK_AXIS_PIN, false);

  //** Define logic with condition and relation
  Relation1to1* relationServo = new Relation1to1(NULL, stepper, xAxis);
  // ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  // Depending on Arduino it needs a short delay. Do not add any other delays!
  delay(5);
}
⚠️ **GitHub.com Fallback** ⚠️