#include <LiquidCrystal_I2C.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
AccelStepper stepperR; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepperL(AccelStepper::FULL4WIRE,19,18,5,4);
MultiStepper steppers;
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
const byte PositionPot = 12;
const byte AccelerationPot = 13;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
void setup(){
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
stepperR.setMaxSpeed(1000);
stepperR.setAcceleration(35);
stepperL.setMaxSpeed(1000*5);
stepperL.setAcceleration(35);
// Then give them to MultiStepper to manage
steppers.addStepper(stepperL);
steppers.addStepper(stepperR);
}
void loop(){
long position = analogRead(PositionPot);
int accel = analogRead(AccelerationPot);
long positions[2]; // Array of desired stepper positions
positions[0] = 50 * position;
positions[1] = -0.5 * position;
stepperR.setAcceleration(accel);
stepperL.setAcceleration(accel);
steppers.moveTo(positions);
//steppers.runSpeedToPosition(); // Blocks until all are in position
steppers.run();
// set cursor to first column, first row
lcd.setCursor(0, 0);
// print message
lcd.print("Stepper Motor!");
delay(1000);
// clears the display to print new message
lcd.clear();
// set cursor to first column, second row
lcd.setCursor(0,1);
lcd.print("Circuit Design:)");
delay(1000);
lcd.clear();
}