Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Countdown Timer

Featured Replies

  • Commercial Member

This is a piece of code (I forget where I found it from) that I've been using as part of my count-down timer:if ( start == 1 ) { chrono = CLOCK_TOTAL_SECONDSvar.var_value.n ; chronoevent = CLOCK_TOTAL_SECONDSvar.var_value.n ; start = 2 ; } if ( start == 2 ) { chronotime = CLOCK_TOTAL_SECONDSvar.var_value.n - chrono ; } else { chronotime = 0 ; } if ( start == 2 ) { chronotimeevent = CLOCK_TOTAL_SECONDSvar.var_value.n - chronoevent ; } else { chronotimeevent = 0 ; } if ( chronotime < 0 ) { chronotime = chronotime + 86400 ; } if ( chronotimeevent < 0 ) { chronoevent = chronoevent + 86400 ; } if ( start == 2 ) { vr = ( chronotime - fmod(chronotime,60) ) / 60 ; } if ( start == 2 ) { eventtime = ( chronotimeevent - fmod(chronotimeevent,60) ) / 60 ; } vr = fmod(vr,60) ; eventtime = fmod(eventtime,60) ; My code for count down timer starts at 45 minutes.The trouble is that when the timer reaches 0 minutes, eventtime will sometimes bounce back up to some random number.It's hard to reproduce. Sometimes it happens. Sometimes it doesn't.Anyone have any ideas?Or does anyone have another count down timer in C that does the same job but which is simpler?Cheers,

This is a piece of code (I forget where I found it from) that I've been using as part of my count-down timer:if ( start == 1 ) { chrono = CLOCK_TOTAL_SECONDSvar.var_value.n ; chronoevent = CLOCK_TOTAL_SECONDSvar.var_value.n ; start = 2 ; } if ( start == 2 ) { chronotime = CLOCK_TOTAL_SECONDSvar.var_value.n - chrono ; } else { chronotime = 0 ; } if ( start == 2 ) { chronotimeevent = CLOCK_TOTAL_SECONDSvar.var_value.n - chronoevent ; } else { chronotimeevent = 0 ; } if ( chronotime < 0 ) { chronotime = chronotime + 86400 ; } if ( chronotimeevent < 0 ) { chronoevent = chronoevent + 86400 ; } if ( start == 2 ) { vr = ( chronotime - fmod(chronotime,60) ) / 60 ; } if ( start == 2 ) { eventtime = ( chronotimeevent - fmod(chronotimeevent,60) ) / 60 ; } vr = fmod(vr,60) ; eventtime = fmod(eventtime,60) ; My code for count down timer starts at 45 minutes.The trouble is that when the timer reaches 0 minutes, eventtime will sometimes bounce back up to some random number.It's hard to reproduce. Sometimes it happens. Sometimes it doesn't.Anyone have any ideas?Or does anyone have another count down timer in C that does the same job but which is simpler?Cheers,
What's the code that (1) sets the time (45 min) and (2) checks when that time's up

Gerry Howard

Try this snippet for a GP timer (no warranty and usual disclaimers!)

/* Definitions */ bool Running; bool TimeUp; long StartTime; long CurrentTime; long ElapsedTime; long LimitTime;  /* If timer not running start it  */ if (!Running)   {   ElapsedTime = 0;   StartTime = time(NULL);   Running = true;   TimeUp = false;   }  /* If timer running update it */ if (Running)   {   ElapsedTime = time(NULL) - StartTime;    // Check if time up   if (ElapsedTime >= LimitTime)	 { 	 TimeUp = true;	 Running = false;	 }   else	 TimeUp = false;   }

Set the required time in LimitTime in seconds, set Running = false, and then check TimeUp to see if it has elapsed. The timer is stopped when time's up so needs restarting.time(NULL) returns the elapsed time in seconds from 00:00:00 GMT, January 1, 1970 so there's no need to worry abiut day end. I imagine that FS time is derived from this.

Gerry Howard

  • 2 weeks later...

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.