TestKeypad

Dependencies:   Hotboards_keypad TextLCD mbed

Fork of Chronometer_V2 by VR FabLab - RoboVal

Files at this revision

API Documentation at this revision

Comitter:
Ghiri
Date:
Thu Nov 23 14:20:48 2017 +0000
Child:
1:26bcd89c18e5
Commit message:
Publication Test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 23 14:20:48 2017 +0000
@@ -0,0 +1,169 @@
+//##############################################################
+//##
+//## Event: RoboVal - Robot Race
+//##
+//## Chronometer double use
+//##
+//## Version 1.99A
+//##
+//## Hardware platform used: ST NUCLEO-F401RE
+//##
+//## Software IDE used: mbed online version
+//##
+//## Organizzation: Verona FabLab
+//##
+//## Date creation: 2018.01.01
+//##
+//## Software developpers: FdF,GV, AG
+//##
+//## Base on original version of by FdF
+//##
+//##############################################################
+
+#include <stdlib.h>
+ 
+#include "mbed.h"
+#include "TextLCD.h"
+ 
+ 
+// Default Number Lap
+#define NUM_LAP 3
+
+// Reference for Low/Min Voltage battery
+#define VBAT_MIN 7.2
+ 
+ 
+typedef struct time_screen {
+   int cents;
+   int seconds;
+   int minutes;
+} measured_time;
+ 
+
+ // read Voltage battery
+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); 
+
+// Sensor connected to digital input D9, alias PC7 on Morpho layout
+InterruptIn proximity(D9); 
+ 
+Timer t;
+
+// LCD Display (RS, E, D4, D5, D6, D7);
+TextLCD lcd(D2,D3,D4,D5,D6,D7); 
+ 
+int lap = 0;
+int last_read = 0;
+int lap_time = 0;
+ 
+ 
+// Conversion from millisecond to mm:ss:cc data format
+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;    
+}
+ 
+// Function to measure time elapsed 
+void measure_time(){
+    int read = t.read_ms();
+    
+    if(lap == 0){
+        t.start();
+        lap++;
+    }else{
+        //Dabouncing per evitare problemi
+        if(read - last_read > 1000){
+            
+            lap_time = read - last_read;
+            
+            if(lap >= NUM_LAP){
+                t.stop();
+                lap++;
+            }else{
+                lap++;
+            }
+            
+            last_read = read;     
+        }
+    }
+    
+}
+
+// Function to reset measure done
+void reset_measure(){
+    t.stop();
+    t.reset();
+    lap = 0;
+    last_read = 0;
+    lcd.cls();
+}
+ 
+ 
+ 
+//------------------------------------------------------------ 
+//
+//       Main body
+//
+//------------------------------------------------------------
+ 
+int main() {
+    
+    proximity.mode(PullDown);
+    proximity.rise(&measure_time);    
+    user_button.fall(&reset_measure);
+    
+  
+   
+    
+    while(true) {
+        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);
+       
+        //Gestione dei parziali
+        if(lap > 1){
+            time = human_read(lap_time);
+            lcd.locate(0,1);
+            lcd.printf("Giro %d %02d:%02d:%02d",lap - 1,time.minutes,time.seconds,time.cents);
+        }
+        
+        heartbeat = !heartbeat;
+        
+        
+        if(lap > 0 && lap <= NUM_LAP){
+            wait(0.1);
+        }else{
+            if(lap == 0){
+                //Controllo batteria con partitore resistivo
+                double battery =  ((3.3L * vbat) * 57) / 10;
+                if(battery < VBAT_MIN){
+                    lcd.locate(0,1);
+                    lcd.printf("LOW BAT %2.1f",battery);
+                }else{
+                    lcd.locate(0,1);
+                    lcd.printf("OK  BAT %2.1f",battery);
+                }
+            }
+            wait(1);
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 23 14:20:48 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file