So here is a short program. Pressing a button (ButtonPin) should end the do while loop but it does not. Any suggestions?
int buttonPin = 11;
int relePin2 = 7;
int relePin3 = 8;
int motorPin = 9;
int LEDPin = 13;
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(relePin2, OUTPUT);
pinMode(relePin3, OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(LEDPin, OUTPUT);
}
void loop() {
buttonState = digitalRead (buttonPin);
digitalWrite (motorPin, LOW);
if (buttonState == LOW)
{
do {
buttonState == digitalRead(buttonPin);
digitalWrite (motorPin, HIGH);
delay (3000);
} while (buttonState == LOW);
digitalWrite(relePin2,HIGH);
delay (2000);
digitalWrite(relePin3,HIGH);
delay (2000);
digitalWrite(relePin3,LOW);
digitalWrite(relePin2,LOW);
}
}
I want my MotorPin to always run for three seconds and than stop when the button is pressed. Thanks for help!