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.
Dependencies: mbed keypadLib TextLCD
Revision 5:47a452a6f248, committed 2018-05-22
- Comitter:
- peps
- Date:
- Tue May 22 20:48:32 2018 +0000
- Parent:
- 4:23472c2b246b
- Child:
- 6:369dafe4ed5e
- Commit message:
- Impedita commutazione di modo se sta misurando.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 22 20:34:09 2018 +0000
+++ b/main.cpp Tue May 22 20:48:32 2018 +0000
@@ -75,8 +75,10 @@
int best_time = -1;
// Pointer to the loop function (depending on the selected mode)
void (*loopMethod)(void);
+// Flag to avoid unwanted mode switch when running
+bool isRunning = false;
-/*** Gestione keypad ****/
+/*** Keypad handling ****/
PinName rowPins[4] = { PA_13, PA_14, PC_2, PC_3 };
PinName colPins[4] = { PA_0, PA_1, PA_4, PB_0 };
@@ -121,9 +123,9 @@
_cols[i] = new DigitalIn(colPins[i],PullDown);
}
}
-/**** fine gestione keypad ****/
+/**** End keypad handling ****/
-//Conversione da millisecondi a mm:ss:cc
+//Convert milliseconds in human-readabe (mm:ss:cc) format
measured_time human_read(int ms){
measured_time read;
div_t qr = div(ms,1000);
@@ -139,9 +141,10 @@
return read;
}
-// Invoked when startGate triggered.
+// Invoked when startGate triggered in SPEED mode.
// Start the timer or read the timer and store lap and best time
void measure_time() {
+ isRunning = true;
int read = t.read_ms();
if(lap == -1){
@@ -187,6 +190,7 @@
time = human_read(best_time);
lcd.locate(0,1);
lcd.printf("Best %d %02d:%02d:%02d",best_lap,time.minutes,time.seconds,time.cents);
+ isRunning = false;
break;
// Default - display last completed lap time
// In case of last lap, wait 1 sec -- next time, best lap will be displayed
@@ -202,12 +206,16 @@
}
}
+// Invoked when startGate triggered in LABIRYNTH mode.
void start_time() {
+ isRunning = true;
lap = 0;
t.start();
}
+// Invoked when endGate triggered in LABIRYNTH mode.
void stop_time() {
+ isRunning = false;
lap = 1;
t.stop();
int read = t.read_ms();
@@ -259,7 +267,10 @@
}
}
+// Reset state and configure current mode
+// Invoked when RESET (#) key pressed on the keypad
void reset_measure(){
+ isRunning = false;
t.stop();
t.reset();
lap = -1;
@@ -294,15 +305,18 @@
heartbeat = !heartbeat;
loopMethod();
wait(0.1);
- key = getKey();
+ key = getKey();
if (key != '\0') {
- if(key == 'A') {
- mode = LABYRINTH;
- reset_measure();
- } else if(key == 'B') {
- mode = SPEED;
- reset_measure();
- } else if(key == '#') {
+ if (!isRunning) {
+ if(key == 'A') {
+ mode = LABYRINTH;
+ reset_measure();
+ } else if(key == 'B') {
+ mode = SPEED;
+ reset_measure();
+ }
+ }
+ if(key == '#') {
reset_measure();
}
}