here it is.
const int solenoid = 10; //Output to solenoid relay
const int Step = 9; //output Stepper motor driver pulse signal
const int step_dir = 8; //output Low=CW High=CCW direction output to step driver
const int button = 7; //input for start button
const int cylswitch = 6; //input cylinder switch
const int stepdirection = 5; //input for direction of stepper motor
int cylstate; //state of solenoid and cylinders it actuates
int buttonstate; //7 state of button high/low input from start button
int dirstate; //5 state of stepper direction high/low input from directional switch
int stepstate; //state of stepper motor pulse
int solstate; //6 state of solenoid high/low
unsigned long overallstarttime;
unsigned long previousmicros; //time tracking variable
unsigned long Timeinterval = 6000000; //overall time interval to run step motor
unsigned long stepinterval = 1; //time per step om motor
unsigned long currenttime;
boolean stepping = true; //statement to control overall time of step motor running
void setup() {
pinMode(button, INPUT_PULLUP);
pinMode(stepdirection, INPUT_PULLUP);
pinMode(cylswitch, INPUT_PULLUP);
pinMode(solenoid, OUTPUT);
pinMode(step_dir, OUTPUT);
pinMode(Step, OUTPUT);
digitalWrite(step_dir, LOW);
digitalWrite(Step, LOW);
overallstarttime = micros();
previousmicros = overallstarttime;
}
void loop() {
//Read states of inputs
dirstate = digitalRead(stepdirection);
buttonstate = digitalRead(button);
cylstate = digitalRead(cylswitch);
//start button is pressed strobe is clamped activating cylswitch input to LOW
if (buttonstate == HIGH) {
solstate = HIGH;
}//start button is not pressed strobe is released
else {
solstate = LOW;
}
//when air cylinder switch and start buttons are active turn on stepper motor with 1 microsencond step time
if ((buttonstate == HIGH) && (cylstate == LOW)) {
currenttime = micros();
if (currenttime - previousmicros > stepinterval && stepping) {
digitalWrite(Step, !digitalRead(Step));
previousmicros = previousmicros + stepinterval;
}
//track 6s time interval for stepper motor to run
if (currenttime - overallstarttime >= Timeinterval && stepping) {
stepping = false;
}
}
//change state of stepping when start button is released after 6 second cycle completed
if (buttonstate == LOW && stepping == false) {
stepping = true;
}
//write output states
digitalWrite(Step, stepstate);
digitalWrite(solenoid, solstate);
digitalWrite(step_dir, dirstate);
}