I am trying to start a loop with the press of a button, I am using the attached code. As soon as I run the rest of the loop begins, regardless of the button press. This is not the case with simple test code below, it works as I had hoped. I can't quite see what I am missing!
// Define
int led = 13;
int led2 = 12;
int led3 = 11;
int motorPin = 2;
int motorPin2 = 3;
int motorPin3 = 4;
int buttonPin = 5; // the number of the pushbutton pin
// the setup routine runs once when you press reset:
void setup() {
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(motorPin, OUTPUT); // setup Agitation Pump
pinMode(motorPin2, OUTPUT); // setup Dev IN Pump
pinMode(motorPin3, OUTPUT); // setup Dev OUT Pump
pinMode(buttonPin, INPUT); // setup Button
}
void loop() {
while (digitalRead(buttonPin) == HIGH) {
delay(3000);
//DEVELOPER
digitalWrite(led, HIGH); // Dev LED on
analogWrite(motorPin2, 200); // Dev FILL pump on for 3 seconds
delay(3000);
analogWrite(motorPin2, 0); // Dev FILL pump off
delay(3000); //Start Process for 3 seconds
analogWrite(motorPin, 200); // Agitate for 3 seconds
delay(3000);
analogWrite(motorPin, 0); // Agitate stop
delay(3000); //Continue process for 3 seconds
analogWrite(motorPin3, 200); // Dev DRAIN pump for 3 seconds
delay(3000);
analogWrite(motorPin3, 0); // Dev DRAIN pump stop
digitalWrite(led, LOW); //Dev LED off
}
}
My proof of concept seems to be working with this code:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
while (digitalRead(buttonPin) == HIGH) {
delay (3000);
digitalWrite(ledPin, HIGH);
}
}