i get it to work using that technique (see code), but how do i time it so it only runs for 6 seconds?
const int solenoid = 10; //Output to solenoid relay
const int Step = 9; //Stepper motor driver pulse signal
const int step_dir = 8; //Low=CW High=CCW direction output to step driver
const int button = 7; //start button and Cylinder switch
const int cylswitch = 6; //cylinder switch
const int stepdirection = 5; //input for direction of stepper motor
int cylstate;
int buttonstate; //state of button high/low input from start button
int dirstate; //state of stepper direction high/low input from directional switch
int stepstate; //state of stepper motor pulse
int solstate; //state of solenoid high/low
long previousmillis = 0;
long interval = 6000;
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);
}
void loop() {
stepstate=digitalRead(stepdirection);
buttonstate=digitalRead(button);
cylstate=digitalRead(cylswitch);
if (stepstate==HIGH){
dirstate=HIGH;} //when switch is on direction is CCW
else{
dirstate=LOW;} //when switch is off direction is CW
if (buttonstate==HIGH){
solstate=HIGH;}//start button is pressed strobe is clamped activating cylswitch input
else{
solstate=LOW;} //start button is not pressed strobe is released
if((buttonstate==HIGH) && (cylstate==LOW)){
digitalWrite(Step,HIGH);;
delayMicroseconds(1);
digitalWrite(Step,LOW);;
delayMicroseconds(1);}
digitalWrite(solenoid,solstate);
digitalWrite(step_dir,dirstate);
}