0

I'm trying to make a timer, and I've set one button as reset button, the other one button as starting the timer. Below you can see some parts of the code that I have now:

  if ( buttonCount == 0 ) {
    t = 180; // 3 mins
    display.clearLine(2);
    int min = t / 60;
    int sec = t % 60;
    sprintf(buf, "%02d:%02d", min, sec);
    display.draw2x2String(2, 3, buf);
  }

// reset button
  if ( deBouncerR.fell() ) {
    buttonCount = 0;
  }

// countdown button
  If (deBouncerT.fell() ) {
      while (t > 0){
      delay(1000);
      t = t - 1;
      display.clearLine(2);
      int min = t / 60;
      int sec = t % 60;
      sprintf(buf, "%02d:%02d", min, sec);
      display.draw2x2String(2, 3, buf);
      }
    }

So here, the time is set in 3 minutes, and once I press the countdown button, other buttons are not working because of while(). I would like to know how to make reset button to break while loop.

Share a link to this question (includes your user id)
| edit | close | undelete |
0

Study this Blog article and the last example given there, as that is very similar to what you want. As said in the lecture and also explained in the Blog article avoid using unnecessary loops and delay()'s.

As you can also see, the 3rd task, check for pressed buttons, is done seperatly from the count-down, which is the second task: update countdown timer every second.

Share a link to this answer (includes your user id)
| edit | undelete |

Not the answer you're looking for? Browse other questions tagged or ask your own question.