Pages: [1]   Go Down
Author Topic: if else if help with time delay  (Read 968 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hello smiley
 i have a problem on my program, what i want is when i press the button the if statement execute then after 10 seconds the else if statement execute but before the 10 seconds time when i repress the button, if statement execute then the timer count again 10sec.
thanks smiley

sample video that i want when he didn't trigger the sensor after a few sencond the lights off smiley)



my program smiley
void loop() {

 
  if(digitalRead(switchPin) == HIGH && button == 0){ /* if D2 is HIGH */
  delay(200);  /* Soft Debounce delay for 500mS */
 
   button = 1;
 //sound
 
  send(0x0001);//play file 0000
  delay(100);//delay 10 seconds
 
  send(0xfff7);//set voice volumn to 7
  delay(300);
   
  //light
 pew();
 
 send(0xfffe);// pause

  } 
  else if(digitalRead(switchPin) == LOW && button == 1){
    button = 0;
     
     
   pewew();
     
   }
   

 
 
 
 
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26240
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
my program
And the rest of it?

Please use code tags when posting code.

Code:
delay(100);//delay 10 seconds
One of those statements is incorrect.
Guess which one the compiler believes.
« Last Edit: October 13, 2012, 01:45:28 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would be beneficial to pay some attention to the blink without delay example, and learn to NOT use delay(). If you get rid of the delay()s, then what you want to accomplish is trivial. Resetting the start time effectively changes the end time, making stopping at the right time a no-brainer.
Logged

Pages: [1]   Go Up
Jump to: