10 years, 1 month ago.

I want to call my timer loop everytime I press start instead of once? how?

<<code>> int main() {

float T= i; float timeleft= T;

lcd.cls(); lcd.locate(1,0); lcd.printf("ENGINE START"); wait(1);

while(timeleft >0){ switchengine=1; if(timeleft<4){ lcd.cls(); lcd.locate(1,0); lcd.printf("Time = %2.2f mn", time*15); wait(0.5); lcd.cls(); } else{ lcd.cls(); lcd.locate(1,0); lcd.printf("Time = %1.2f Hr",(T)*15/60.0); wait(0.5); lcd.cls(); }

lcd.locate(0,1); lcd.printf("Timeleft:%1.2f H",timeleft*15/60.0); wait(900); timeleft; lcd.cls();

} switchengine=0;

<</code>>

Question relating to:

support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets. C027, u-blox

1 Answer

10 years, 1 month ago.

Hi Jay,

If you edit your question and add a line break after the first <<code>> tag, your sample will be easier to read. To start, your code has a lot of syntax errors, which makes it harder to understand your question and offer some direction. If you can get it to compile, then please edit your question and paste the compilable code into it.

So, I'm not sure if I'm offering something helpful by what I do see.

  float T = i; // I suspect this won't compile. Is 'i' a parameter that is passed in, but not shown?
  ...
  wait(900); // This would be a request to wait 900 seconds, was that your intent? Your other wait factors are quite small by comparison.
  timeleft--; // Since timeleft is a float, this will subtract 1, and any fraction is mostly unchanged. Is that your intent?

To your basic question - "to call my timer loop everytime I press start instead of once?"

The cookbook pages offer a lot of information to get started. Here's a few links:

  • Digital IO read about DigitalIn in particular if that is how you have your start signal connected.
  • Timers has good information on measuring time. In particular, Timer and Ticker both might be useful. Ticker perhaps to update the display on a regular basis, and Timer for more precision in timing.
  • Watchdog could be of use to you. Any system that controls something would commonly benefit from a watchdog - if the s/w were to crash and get stuck, the watchdog can force a special reset. Whenever you get a reset, you might want to "turn off" the device under control as one of the first steps.

Accepted Answer

thank you Mr. David for taking your time out to help me. I am actually making a timer with a 15 min resolution(900 secs). Total wait is 50 hour. The reason to call the timer loop at [previous setting by pressing start again is to avoid setting of time again and just restart with the previously set time period. I tried creates attaching the void function with a button press but it shows an error "no instance of overloaded function "mbed::Serial::attach" matches the argument list" in file "drv/serial/buf/SerialBuf.cpp"...please help me as i am not able to understand this problem

posted by jayendra mishra 19 Jul 2015