Robin2 ... here is the code with steeper.run removed.
#include <EEPROM.h>
#include <AccelStepper.h>
AccelStepper stepper (1, 8, 9);
const int progButton = 2;
const int rotoS = 3;
const int rotoM = 4;
const int rotoL = 5;
const int rotoO = 6;
const int rotoP = 7;
const int endStop = 10;
const int startButton = 12;
const int homeButton = 11;
byte endStopState = 0;
byte startButtonState = 0;
byte homeButtonState = 0;
byte progButtonState = 0;
byte rotoSState = 0;
byte rotoMState = 0 ;
byte rotoLState = 0;
byte rotoOState = 0;
byte rotoPState = 0;
int long i = 0;
int long p = 0;
int k = 0;
int addr = 0;
void setup() {
pinMode(progButton, INPUT);
pinMode(endStop, INPUT);
pinMode(startButton, INPUT);
pinMode(homeButton, INPUT);
pinMode(rotoS, INPUT);
pinMode(rotoM, INPUT);
pinMode(rotoL, INPUT);
pinMode(rotoO, INPUT);
pinMode(rotoP, INPUT);
EEPROM.begin();
Serial.begin(115200);
stepper.setMaxSpeed(5000);
stepper.setAcceleration(800);
}
void loop() {
homeButtonState = digitalRead(homeButton);
if (homeButtonState == HIGH) {
Home();
}
rotoSState = digitalRead(rotoS);
startButtonState = digitalRead(startButton);
if ((startButtonState == HIGH) && (rotoSState == HIGH)) {
Small();
}
rotoMState = digitalRead(rotoM);
startButtonState = digitalRead(startButton);
if ((rotoMState == HIGH) && (startButtonState == HIGH)) {
Mid();
}
rotoLState = digitalRead(rotoL);
startButtonState = digitalRead(startButton);
if ((rotoLState == HIGH) && (startButtonState == HIGH)) {
Large();
}
rotoOState = digitalRead(rotoO);
startButtonState = digitalRead(startButton);
if ((rotoOState == HIGH) && (startButtonState == HIGH)) {
stepper.setMaxSpeed(4000);
stepper.setAcceleration(500);
stepper.moveTo(p);
p = p + 1;
stepper.run(); // Start moving the stepper
rotoPState = digitalRead(rotoP);
progButtonState = digitalRead(progButton);
if ((rotoPState == HIGH) && (progButtonState == HIGH)) {
EEPROM.put(addr, p);
}
}
rotoPState = digitalRead(rotoP);
startButtonState = digitalRead(startButton);
if ((rotoPState == HIGH) && (startButtonState == HIGH)) {
Prog();
}
stepper.run();
}
/////////////////// Function to bring the sled in to the home position. //////////////////
void Home() {
while (digitalRead(homeButtonState)) {
endStopState = digitalRead(endStop);
if (endStopState == LOW) {
stepper.moveTo(-5000);
//stepper.run(); // Start moving the stepper
} else {
stepper.setMaxSpeed(0);
stepper.setCurrentPosition(0);
homeButtonState = 0;
break;
}
}
}
//////////////////// Function to fill the small syringe to it's maximum. ////////////////////
void Small() {
for (i = 0; i <= 7600; i++) {
stepper.setMaxSpeed(4000);
stepper.setAcceleration(500);
stepper.moveTo(i); //Number for small syringe 24500
/* if (i == 7600) {
stepper.stop();
} */
stepper.setCurrentPosition(0);
//stepper.run(); // Start moving the stepper
}
}
//////////////////// Function to fill the medium syringe to it's maximum. /////////////////
void Mid() {
for (i = 0; i <= 7500; i++) {
stepper.setMaxSpeed(5000);
stepper.setAcceleration(800);
stepper.moveTo(i);
stepper.setCurrentPosition(0);
// stepper.run(); // Start moving the stepper
}
}
///////////////////// Function to fill the large syringe to it's maximum. ///////////////////
void Large() {
for (i = 0; i <= 8900; i++) {
stepper.setMaxSpeed(5000);
stepper.setAcceleration(800);
stepper.move(i);
stepper.setCurrentPosition(0);
// stepper.run(); // Start moving the stepper
}
}
///////////////// Function to read from eeprom. ///////////////////////
void Prog() {
EEPROM.get(addr, p);
stepper.setMaxSpeed(5000);
stepper.setAcceleration(800);
stepper.move(p);
Serial.println(p);
//stepper.run(); // Start moving the stepper
}