Go Down

Topic: Trouble with programming logic (Read 1 time) previous topic - next topic


Well, you need return. You also could use more Serial.print() statements to determine what is going on.

Finally, you need to comment the count() function better (after changing to while statements), and explain what you want the function to do, when.
The art of getting good answers lies in asking good questions.


You have to count down from what maximum?


Jan 21, 2013, 03:16 am Last Edit: Jan 21, 2013, 07:36 am by lloyddean Reason: 1
Well, in the interest of indirect help see if this makes any sense to you.
TIme has been scaled per your earlier statement of 1 second equals 1 minute (or so I interpreted it as - if not change the value of 'ONE_SECOND').

Code: [Select]

const unsigned long ONE_SECOND  = 16UL;
const unsigned long ONE_MINUTE  = 60 * ONE_SECOND;
const unsigned long ONE_HOUR    = 60 * ONE_MINUTE;

unsigned long msTarget;

unsigned long hms2millisecs(uint8_t const hours, uint8_t const minutes, uint8_t const seconds)
   return ((hours * ONE_HOUR) + (minutes * ONE_MINUTE) + (seconds * ONE_SECOND));

void millisecs2hms(unsigned long milliseconds, uint8_t* hours, uint8_t* minutes, uint8_t* seconds)
   uint8_t h = milliseconds / ONE_HOUR;        milliseconds -= h * ONE_HOUR;       *hours      = h;
   uint8_t m = milliseconds / ONE_MINUTE;      milliseconds -= m * ONE_MINUTE;     *minutes    = m;
   uint8_t s = milliseconds / ONE_SECOND;      milliseconds -= s * ONE_SECOND;     *seconds    = s;

void loop()
   uint8_t     hours;
   uint8_t     minutes;
   uint8_t     seconds;
   long        remaining = msTarget - millis();
   millisecs2hms(remaining, &hours, &minutes, &seconds);


   if ( remaining <= 0 )
       // we've reached zero time
       while (true)
       {    }

void setup()
   msTarget = millis() + hms2millisecs(1, 50, 54); // hours, minutes, seconds

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131