Pages: [1]   Go Down
Author Topic: if else if help with time delay  (Read 980 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 30
View Profile
 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;
  send(0x0001);//play file 0000
  delay(100);//delay 10 seconds
  send(0xfff7);//set voice volumn to 7
 send(0xfffe);// pause

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


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

my program
And the rest of it?

Please use code tags when posting 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
Online Online
Brattain Member
Karma: 615
Posts: 49388
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.

Pages: [1]   Go Up
Jump to: