Hello All,
I'm still a newbie with Arduino programming. What I'm trying to accomplish below is for an LED to flash on/off (when a PIR motion is detected) until either the # of times is reached OR a pushbutton is depressed. So far, the flashing LED works fine when motion is detected, however, I can't seem to break the WHILE loop with input from the pushbutton. What am I doing wrong?
void loop()
{
buttonState = digitalRead(resetbutton);
senseMotion = digitalRead(motionPin);
// Everything is fine
if (senseMotion == LOW) // no motion detected
{
digitalWrite(SafePin, HIGH); // Light the Safe LED
digitalWrite(AlarmPin, LOW); // Turn off the Alarm LED
}
// Sense for Motion -------------------------------------------------------------------
if (senseMotion == HIGH)
{
digitalWrite(SafePin, LOW); // Turn off the Safe Pin
int x=0;
while (x < 200 && buttonState == LOW)
{
digitalWrite(AlarmPin, HIGH);
delay(100);
digitalWrite(AlarmPin, LOW);
delay(100);
x++;
}
}