5

We're trying to pause the timer block, and then have it restart at the same time where it left off.

By using the touch sensor in a loop before our timer code we were able to get the text output to stop and restart, however on restart the text output just jumps to the current timer output, so it's clear we're not actually pausing the timer output.

Any ideas on how to pause and restart the timer block using the touch sensor?

Here's our code: enter image description here

1 Answer 1

4

I don't think there is a shortcut. The timer sensors record how much time has elapsed since they were reset. The starting of the program gives you the first reset for free. So the psuedocode ends up something like this. The button touched vs released is a personal preference. I think of the interval as starting when the button is released and extending until it is pressed.

  • Set a variable "totalTime" to zero
  • Loop start
  • wait for button touched
  • Set a variable "intervalTime" = timer sensor value
  • Set "totalTime" = "intervalTime" + "totalTime"
  • Set intervalTime = 0
  • wait for button to be released
  • write to the LCD display "ready for next interval"
  • wait for button to be touched
  • wait for button to be released
  • reset the timer sensor
  • Loop end (forever)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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