Basically, when the "if" condition is true, I would like all of the following to occur at once:
- An LCD display will show text
- An LED will blink on and off at regular intervals
- A speaker will alternate between two notes, also at regular intervals.
- All of this will occur for x times before stopping.
Here's a simplified version of the code:
int value; void setup () {}
void loop() {
if (value >= 10 ){
for (int x = 0; x<500: x++); {
// LCD
lcd.clear();
lcd.home();
lcd.print("WARNING:");
lcd.setCursor(0,1);
lcd.print("Intruder Alert");
// LED
if (timerLED > intervalLED1) {
timerLED -= intervalLED1; //reset timer
digitalWrite(LEDPin, !digitalRead(LEDPin));
}
// SPEAKER
switch(note)
{
case 0: //for first note
tone (SpeakerPin,262,250);
break;
case 1: //for second note
tone (SpeakerPin,310,250);
break;
}
if (timerMUSIC >= intervalMUSIC1)
{
timerMUSIC -= intervalMUSIC1;
note = !note;
}
}
}
} // E N D
What I get is this instead: [youtube video]
I think it's because all the desired actions (I'll refer to them as DA) are placed in a loop function under an if statement, hence once the if statement becomes false the entire DA will be skipped, causing the sudden stops as seen in the video.
I've tried placing the DA into a separate function and getting the "if" statement to call that function, but somehow none of the DA will be executed in that situation, even when the "if" statement is true.
How do I make the DA repeat x no. of times the moment the if statement is true? Thanks in advance.