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 7:f687eda36aec, committed 2019-04-10
- Comitter:
- peps
- Date:
- Wed Apr 10 22:09:13 2019 +0000
- Parent:
- 6:369dafe4ed5e
- Commit message:
- Removed trailing blanks :-)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Apr 10 22:03:07 2019 +0000 +++ b/main.cpp Wed Apr 10 22:09:13 2019 +0000 @@ -42,25 +42,25 @@ int seconds; int minutes; } measured_time; - + // Heartbeat LED DigitalOut heartbeat(LED1); // read Voltage battery, analog pin used PC_3 (Pin 37 of Morpho layout) //AnalogIn vbat(PC_3); - -// User button pressure -InterruptIn user_button(USER_BUTTON); + +// User button pressure +InterruptIn user_button(USER_BUTTON); // Gates connected to digital input PA_15 and PB_7 -InterruptIn gateStart(PA_15), gateEnd(PB_7); +InterruptIn gateStart(PA_15), gateEnd(PB_7); // LCD Display (RS, E, D4, D5, D6, D7); -TextLCD lcd(D2,D3,D4,D5,D6,D7); +TextLCD lcd(D2,D3,D4,D5,D6,D7); // Timer for the chrono function Timer t; - + // Number of laps int lap = -1; @@ -93,7 +93,7 @@ DigitalIn* _cols[4]; // Define your own keypad values -char Keytable[] = { +char Keytable[] = { '1', '2', '3', 'A', // r0 '4', '5', '6', 'B', // r1 '7', '8', '9', 'C', // r2 @@ -137,16 +137,16 @@ measured_time human_read(int ms){ measured_time read; div_t qr = div(ms,1000); - + read.cents = qr.rem % 100; - + qr = div(qr.quot,60); read.seconds = qr.rem; - + qr = div(qr.quot,60); read.minutes = qr.rem; - - return read; + + return read; } // Invoked when startGate triggered in SPEED mode. @@ -167,26 +167,26 @@ best_time = lap_time; best_lap = lap; } - + if(lap >= NUM_LAP) { t.stop(); } - + last_read = read; } - } + } } // Handler for loop when in SPEED mode void speedLoop() { - int read = t.read_ms(); - + int read = t.read_ms(); + measured_time time = human_read(read); - + lcd.locate(0,0); lcd.printf("Totale %02d:%02d:%02d",time.minutes,time.seconds,time.cents); - // Handle lap time display + // Handle lap time display switch(lap) { // only display time if at least 1 lap completed case -1: @@ -225,10 +225,10 @@ isRunning = false; lap = 1; t.stop(); - int read = t.read_ms(); - + int read = t.read_ms(); + measured_time time = human_read(read); - + lcd.cls(); lcd.locate(0,0); lcd.printf("Finish!"); @@ -239,7 +239,7 @@ } void labyrinthLoop() { - int read = t.read_ms(); + int read = t.read_ms(); measured_time time = human_read(read); lcd.locate(0,1); lcd.printf("Elapsed %02d:%02d:%02d",time.minutes,time.seconds,time.cents); @@ -258,7 +258,7 @@ lcd.printf("Mode: LABYRINTH "); wait(1); break; - + case SPEED: default: gateStart.enable_irq(); @@ -289,7 +289,7 @@ void switchMode() { mode = mode == SPEED ? LABYRINTH : SPEED; - reset_measure(); + reset_measure(); } void test_keyboard() { @@ -311,7 +311,7 @@ } } -//------------------------------------------------------------ +//------------------------------------------------------------ // // Main body //