Example 13‐Stepper motor with variable speed - GSTCH/SketchMadeEASY GitHub Wiki
Stepper motor speed in relation to a potentiometer. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Examples/13-StepperMotorWithVariableSpeed".
Sketch Made EASY supports controlling stepper motors by different chips (shields):


#include <Easy.h>
//*****************************************************************
// H-Bridge shield like L9110, ULN2003, ...
#define HBRIDGE_PIN1 9
#define HBRIDGE_PIN2 10
#define HBRIDGE_PIN3 11
#define HBRIDGE_PIN4 12
// Stepper Motor: 28BYJ-48
#define STEPS_PER_ROTATION 32
#define GEAR_RATIO 64
#define STEPPER_RESOLUTION STEPS_PER_ROTATION * GEAR_RATIO
// Potentiometer
#define VARIABLE_INPUT_PIN A0
void setup()
{
//((*** Initialize: Configure your sketch here....
//** Define Actuators:
Actuator* stepper = new MotorStepperRotate(HBRIDGE_PIN1, HBRIDGE_PIN2, HBRIDGE_PIN3, HBRIDGE_PIN4, STEPPER_RESOLUTION);
//** Define Input
// Variable input sets the rotation speed of the motor.
Input* poti = new VariableInput(VARIABLE_INPUT_PIN);
//** Define logic with condition and relation
// No condition (NULL) because the relation is always active
Relation* relation = new Relation1to1(NULL, stepper, poti);
// ***))
// 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);
}

#include <Easy.h>
//*****************************************************************
// Adafruit MotorShield V2
#define STEPPER_NR 2
#define MAX_CYCLES_PER_SECOND 1000
// Stepper motor: 28BYJ-48
#define STEPS_PER_ROTATION 32
#define GEAR_RATIO 64
#define STEPPER_RESOLUTION STEPS_PER_ROTATION * GEAR_RATIO
// Potentiometer
#define VARIABLE_INPUT_PIN A0
void setup()
{
//((*** Initialize: Configure your sketch here....
//** Define Actuators:
Actuator* stepper = new MotorStepperRotateI2C(STEPPER_NR, STEPPER_RESOLUTION, MAX_CYCLES_PER_SECOND);
//** Define Input
// Variable input sets the rotation speed of the motor.
Input* poti = new VariableInput(VARIABLE_INPUT_PIN);
//** Define logic with condition and relation
// No condition (NULL) because the relation is always active
Relation* relation = new Relation1to1(NULL, stepper, poti);
// ***))
// 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);
}