Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of kl46z_stop_watch_v2 by
Revision 2:8b92d65b8748, committed 2016-10-18
- Comitter:
- eseifert
- Date:
- Tue Oct 18 22:58:32 2016 +0000
- Parent:
- 1:0d13b6d7907f
- Commit message:
- KL46z Stopwatch v3 w/reset
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 12 15:55:44 2016 +0000
+++ b/main.cpp Tue Oct 18 22:58:32 2016 +0000
@@ -1,5 +1,5 @@
#include "mbed.h"
-#include <math.h>
+#include <math.h>
#include "SLCD.h"
#define LEDON false
@@ -9,13 +9,13 @@
#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
#define FULLMINUTE 60 //seconds
#define PROGNAME "kl46z_stop_watch_v1\n\r"
-#define LCDTITLE "STPW"
+#define LCDTITLE "SWTR"
#define TITLEWAIT 2.0
//#define PRINTDBUG // uncomment if printing to serial port desired
@@ -27,28 +27,29 @@
DigitalIn buttons[NUMBUTS] = {RBUT, LBUT};
int displayState = STOPPEDSTATE;
-
-
-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 i;
+int main(void)
+{
char lcdData[LCDCHARLEN];
PwmOut gled(LED_GREEN);
PwmOut rled(LED_RED);
@@ -57,63 +58,61 @@
int minutesCount; // for displaying mininuts
int seconds; //
int fifthSeconds;
- bool statetoggle = false; //was in stopped state.
-
+ 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
- if(!buttons[i]) { // a buttton is pressed
- displayState = i;
- switch (displayState){ // this keeps things generic
- case TIMINGSTATE: {
- statetoggle = !statetoggle;
- break;
- }
- case RESETTINGSTATE :{
- break;
- }
- }
- } // if ! buttons
- }// for loop to look at buttons
+ while (true) {
+ if (ButtonTimer > BUTTONTIME) {
+ // Left button: Start Timing (buttons[0])
+ // Right button: Stop Timing (buttons[1])
+ // Both buttons: Reset Timing (both buttons)
+ if (!buttons[0] && buttons[1]) {
+ displayState = 0;
+ stateToggle = 0;
+ }
+ if (buttons[0] && !buttons[1]) {
+ displayState = 1;
+ stateToggle = 1;
+ }
+ if (!buttons[0] && !buttons[1]) {
+ displayState = 2;
+ stateToggle = 0;
+ }
+
ButtonTimer.reset();
- switch (displayState){
- /* this goes away
- case STOPPEDSTATE : {
- rled = 0.0;
- gled = 1.0;
- break;
+
+ switch (displayState) {
+ case STOPPEDSTATE:
+ rled = 0.0;
+ gled = 1.0;
+ break;
+ case TIMINGSTATE:
+ if(stateToggle) {
+ secondsCount = secondsCount + BUTTONTIME;
}
- */
- case RESETTINGSTATE:
- if (!statetoggle){
- secondsCount = 0;
- displayState = TIMINGSTATE;
- }
- rled = 0.0;
- gled = 1.0;
- break;
-
-
- case TIMINGSTATE : {
- if(statetoggle){
- secondsCount = secondsCount + BUTTONTIME;
- }
- rled = 1.0;
- gled = 0.0;
- break;
+ rled = 1.0;
+ gled = 0.0;
+ break;
+ case RESETTINGSTATE:
+ pc.printf("reset2\r\n");
+ if (!stateToggle) {
+ secondsCount = 0;
+ displayState = STOPPEDSTATE;
}
+ rled = 0.0;
+ gled = 0.0;
+ break;
}
-
+
// 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,"%1d.%02d.%1d",minutesCount,seconds,fifthSeconds);
+ LCDMess(lcdData);
}// end Button timer
}
}
\ No newline at end of file
