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
Diff: main.cpp
- Revision:
- 6:369dafe4ed5e
- Parent:
- 5:47a452a6f248
- Child:
- 7:f687eda36aec
--- a/main.cpp Tue May 22 20:48:32 2018 +0000 +++ b/main.cpp Wed Apr 10 22:03:07 2019 +0000 @@ -4,7 +4,7 @@ //## //## Chronometer double use //## -//## Version 1.99A +//## Version 2.1.1 //## //## Hardware platform used: ST NUCLEO-F401RE //## @@ -14,7 +14,7 @@ //## //## Date creation: 2018.01.01 //## -//## Software developpers: FdF,GV, AG +//## Software developpers: FdF,GV,AG //## //## Base on original version of by FdF //## @@ -31,8 +31,6 @@ #define VBAT_MIN 7.2 // Different function modes -// Switch among them using the USER button -// (waiting for the keypad to work properly) enum modes { LABYRINTH, SPEED @@ -65,19 +63,28 @@ // Number of laps int lap = -1; + // Best lap int best_lap = 0; + // Last time read int last_read = 0; + // Last lap time int lap_time = 0; + // Best lap time 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; +// Version string (max 16 chars) +const char * VERSION_STRING = "Firmware v.2.1.1"; +const char * VERSION_DATE = "Date: 2019.04.10"; /*** Keypad handling ****/ PinName rowPins[4] = { PA_13, PA_14, PC_2, PC_3 }; PinName colPins[4] = { PA_0, PA_1, PA_4, PB_0 }; @@ -96,9 +103,9 @@ int getKeyIndex() { int result = -1; - for (int r = 0; r < 4; r++) { + for (int r = 0; r < 4 && result == -1; r++) { _rows[r]->write(1); - for(int c = 0;c < 4 ;c++){ + for(int c = 0;c < 4 && result == -1;c++){ DigitalIn *col = _cols[c]; if(col->read() == 1) { result = r*4+c; @@ -106,6 +113,7 @@ } _rows[r]->write(0); } + wait_ms(100); return result; } @@ -147,13 +155,12 @@ isRunning = true; int read = t.read_ms(); - if(lap == -1){ + if(lap == -1) { t.start(); lap++; - }else{ - //Dabouncing per evitare problemi - if(read - last_read > 1000){ - + } else { + //Debouncing per evitare problemi + if(read - last_read > 1000) { lap++; lap_time = read - last_read; if (best_time < 0 || lap_time < best_time) { @@ -165,7 +172,7 @@ t.stop(); } - last_read = read; + last_read = read; } } } @@ -285,6 +292,25 @@ reset_measure(); } +void test_keyboard() { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Test Keyboard"); + wait_ms(500); + char key; + while(1) { + key = getKey(); + if (key == 'D') { + lcd.cls(); + return; + } + if (key != '\0') { + lcd.locate(0,1); + lcd.printf("Key pressed: %c", key); + } + } +} + //------------------------------------------------------------ // // Main body @@ -304,9 +330,12 @@ while(true) { heartbeat = !heartbeat; loopMethod(); - wait(0.1); + wait_ms(100); key = getKey(); if (key != '\0') { + if(key == '#') { + reset_measure(); + } if (!isRunning) { if(key == 'A') { mode = LABYRINTH; @@ -314,12 +343,18 @@ } else if(key == 'B') { mode = SPEED; reset_measure(); + } else if (key == '*') { + lcd.cls(); + lcd.locate(0,0); + lcd.printf(VERSION_STRING); + lcd.locate(0,1); + lcd.printf(VERSION_DATE); + wait(3); + lcd.cls(); + } else if (key == 'D') { + test_keyboard(); } } - if(key == '#') { - reset_measure(); - } } } } -