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

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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