Stanley Cohen
/
minutetimer_v2
Kitchen Timer example program.
Fork of secondtimer_v1 by
Revision 4:b6d2c5d48ef0, committed 2015-04-06
- Comitter:
- scohennm
- Date:
- Mon Apr 06 14:30:10 2015 +0000
- Parent:
- 3:db1dad0e5441
- Commit message:
- Use modulus operator for true time calculations
Changed in this revision
minutetimerv2.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r db1dad0e5441 -r b6d2c5d48ef0 minutetimerv2.cpp --- a/minutetimerv2.cpp Sun Apr 05 22:03:56 2015 +0000 +++ b/minutetimerv2.cpp Mon Apr 06 14:30:10 2015 +0000 @@ -11,7 +11,7 @@ #define MAXMIN 55 #define LEDON false #define LEDOFF true -#define SECSPERMIN 59 // counting from zero +#define SECSPERMIN 60 // using modulus // Define states #define NOBLINK 0 // "done" condition #define BLINK 1 @@ -20,8 +20,8 @@ SLCD slcd; //define LCD display TSISensor tsiScaling; // Capacitive sensor/slider -DigitalIn RtButton(PTC12); -DigitalIn LftButton(PTC3); +DigitalIn RtButton(PTC3); +DigitalIn LftButton(PTC12); DigitalOut greenColor(LED_GREEN); DigitalOut redColor(LED_RED); @@ -62,6 +62,7 @@ float tempValue; // for touch value int mCount = MAXMIN; int secCount = SECSPERMIN; + int totalSecs= 0; // define two state machine variables int IndicatorState = NOBLINK; int TimerState = PERIODSELECT; @@ -91,12 +92,12 @@ mCount = int((float)MAXMIN *tempValue); // get minutes sprintf (lcdData,"%d",mCount); LCDMessNoDwell(lcdData); - mCount--; // counter starts at one second less that minutes wait(TOUCHDELAY); } if(RButtonState) { //start the timer SecondsTimer.reset(); - secCount = SECSPERMIN + 1; // 1st time through + // secCount = SECSPERMIN + 1; // 1st time through + totalSecs = mCount * SECSPERMIN; TimerState = TIMING; } break; @@ -104,14 +105,12 @@ case TIMING: { if (SecondsTimer.read() > ONESEC) { - secCount--; - if (secCount == 0){ - mCount--; - secCount = SECSPERMIN; - if(mCount < 0){ - IndicatorState = BLINK; - TimerState = PERIODSELECT; - } + totalSecs--; + mCount = totalSecs / SECSPERMIN; // Quotient + secCount = totalSecs % SECSPERMIN; // Remainder + if(totalSecs < 0){ + IndicatorState = BLINK; + TimerState = PERIODSELECT; } sprintf (lcdData,"%2d%2d",mCount, secCount); // Display countdown LCDMessNoDwell(lcdData);