AnnaLouise Martinez
/
kl46z_stop_watch_v2
AMart_SSD341_hw9.2
Fork of kl46z_stop_watch_v2 by
Diff: main.cpp
- Revision:
- 2:de155cad0909
- Parent:
- 1:0d13b6d7907f
--- a/main.cpp Wed Oct 12 15:55:44 2016 +0000 +++ b/main.cpp Wed Oct 19 04:36:35 2016 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" -#include <math.h> +#include <math.h> #include "SLCD.h" #define LEDON false @@ -9,7 +9,7 @@ #define RBUT PTC3 #define STOPPEDSTATE 0 #define TIMINGSTATE 1 -#define RESETTINGSTATE 0 +#define RESETTINGSTATE 2 #define PRINTDELTA 0.01 #define LCDCHARLEN 10 #define BUTTONTIME 0.2 @@ -29,25 +29,29 @@ -void initialize_global_vars(){ +void initialize_global_vars() +{ pc.printf(PROGNAME); // set up DAQ timer // set up DAQ timers ButtonTimer.start(); - ButtonTimer.reset(); -} + ButtonTimer.reset(); +} -void LCDMess(char *lMess){ - slcd.Home(); - slcd.clear(); - slcd.printf(lMess); +void LCDMess(char *lMess) +{ + slcd.Home(); + slcd.clear(); + slcd.printf(lMess); } -void showTitle(){ +void showTitle() +{ LCDMess(LCDTITLE); wait(TITLEWAIT); return; } -int main(void) { +int main(void) +{ int i; char lcdData[LCDCHARLEN]; PwmOut gled(LED_GREEN); @@ -58,35 +62,30 @@ int seconds; // int fifthSeconds; bool statetoggle = false; //was in stopped state. - + initialize_global_vars(); showTitle(); - while (true) { - if (ButtonTimer > BUTTONTIME){ - for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1 + while (true) { + if (ButtonTimer > BUTTONTIME) { + for (i=0; i<NUMBUTS; i++) { // index will be 0 or 1 if(!buttons[i]) { // a buttton is pressed - displayState = i; - switch (displayState){ // this keeps things generic - case TIMINGSTATE: { - statetoggle = !statetoggle; - break; - } - case RESETTINGSTATE :{ - break; - } - } + displayState = i; } // if ! buttons + else{ + if(!buttons[i]){ + { + if(!buttons[i + 1]){ + displayState = 2; + } + if(!buttons[i-1]){ + displayState = 2; + } } + } + } }// for loop to look at buttons - ButtonTimer.reset(); + switch (displayState){ - /* this goes away - case STOPPEDSTATE : { - rled = 0.0; - gled = 1.0; - break; - } - */ case RESETTINGSTATE: if (!statetoggle){ secondsCount = 0; @@ -95,25 +94,33 @@ rled = 0.0; gled = 1.0; break; - - case TIMINGSTATE : { + statetoggle = !statetoggle; if(statetoggle){ - secondsCount = secondsCount + BUTTONTIME; - } + secondsCount = secondsCount + BUTTONTIME; + } rled = 1.0; gled = 0.0; break; } + case STOPPEDSTATE : { + + displayState = RESETTINGSTATE; + + rled = 0.0; + gled = 1.0; + break; + } } - + ButtonTimer.reset(); // Parse the seconds seconds = (int)secondsCount; // make seconds "mask" fifthSeconds = (int)((secondsCount - (float)seconds) * 10); // the 0.2 seconds minutesCount = seconds / FULLMINUTE; - seconds = seconds % FULLMINUTE; - sprintf (lcdData,"%1d.%02d.%1d",minutesCount,seconds,fifthSeconds); - LCDMess(lcdData); + seconds = seconds % FULLMINUTE; + sprintf (lcdData,"\r\n%1d.%02d.%1d \r\n",minutesCount,seconds,fifthSeconds); + pc.printf (lcdData,"\r\n%1d.%02d.%1d","\r\n",minutesCount,seconds,fifthSeconds); + LCDMess(lcdData); }// end Button timer } -} \ No newline at end of file +}