hi everyone. I'm having a bit of a problem adding a function to my sketch that cancels everything that my relay board is doing as an emergency stop. here is the pertinent code.
void loop() { if (digitalRead(prog2) == HIGH) {program2();} }
void program2() { while (digitalRead(xLimit) != HIGH) xPass1();
while (digitalRead(yPos2) != HIGH) yMove1();
while (digitalRead(xHome) != HIGH) xPass2();
while (digitalRead(xHome) != LOW) allStop(); }
void xPass1() { digitalWrite(4, LOW); delay(50); digitalWrite(2,HIGH); }
void xPass2() { digitalWrite(4,LOW); delay(50); digitalWrite(3,HIGH); }
void yMove2() { digitalWrite(3,LOW); delay(50); digitalWrite(4,HIGH); }
void allStop() { digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,LOW); digitalWrite(8,LOW); }
I want to be able to call the allStop() function at any time. it works a little bit when I add the following:
void xPass1() { if (digitalRead(emergencyStop) == LOW) { digitalWrite(4, LOW); delay(50); digitalWrite(2,HIGH); } else if (digitalRead(emergencyStop) == HIGH) allStop(); }
but it only calls the allStop() function as long as I am pressing the button. Any suggestions?