Give my Version a try: ![]()
#include <Stepper.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
int buttonPullupPin_0 = 11;
int butonPullupPin_1 = 10;
int val_0 = 0;
int val_1 = 0;
unsigned long timeStart; //NEW
unsigned int timeEnd = 2000; //NEW
bool timing = false; //NEW
AccelStepper stepper(AccelStepper::DRIVER, 4, 3);
void setup()
{
pinMode(buttonPullupPin_0, INPUT);
pinMode(butonPullupPin_1, INPUT);
stepper.setMaxSpeed(100);
stepper.setSpeed(90);
stepper.setEnablePin(9);
stepper.disableOutputs();
}
void loop()
{
val_0 = digitalRead(buttonPullupPin_0);
val_1 = digitalRead(butonPullupPin_1);
if(val_1 == LOW) //NEW
timeStart = millis(); //NEW
if(millis() - timeStart < timeEnd) //NEW
timing = true; //NEW
else timing = false; //NEW
if (val_0 == HIGH)
{
stepper.enableOutputs();
}
if (val_1 == LOW)
{
stepper.runSpeed(); //I want to continue this action until val_1 == hight plus a certain time delay
}
// NEW_____________
if (val_1 == HIGH && timing == false) // here i want after reading the button to delay the execution without stopping action before a certain time then execute the action that is conditioned by reading this state of butonPullupPin_1
{
stepper.disableOutputs();//I want to delay this action against reading (val_1 == HIGH)
}
}