Versione modificata con sensore e IR LED a 38kHz.

Dependencies:   TextLCD keypadLib mbed

Fork of Chronometer_V2 by VR FabLab - RoboVal

Revision:
6:853da83fe5a9
Parent:
5:47a452a6f248
--- a/main.cpp	Tue May 22 20:48:32 2018 +0000
+++ b/main.cpp	Thu May 24 22:13:20 2018 +0000
@@ -54,8 +54,11 @@
 // 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); 
+// Gate connected to digital input PA_15
+InterruptIn gateStart(PA_15);
+
+// IR LED connected to PWM out PB_7
+PwmOut IRLED(PB_7);
 
 // LCD Display (RS, E, D4, D5, D6, D7);
 TextLCD lcd(D2,D3,D4,D5,D6,D7); 
@@ -65,16 +68,22 @@
  
 // 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;
 
@@ -213,50 +222,15 @@
     t.start();
 }
 
-// Invoked when endGate triggered in LABIRYNTH mode.
-void stop_time() {
-    isRunning = false;
-    lap = 1;
-    t.stop();
-    int read = t.read_ms(); 
-    
-    measured_time time = human_read(read);
-    
-    lcd.cls();
-    lcd.locate(0,0);
-    lcd.printf("Finish!");
-    lcd.locate(0,1);
-    lcd.printf("Totale %02d:%02d:%02d",time.minutes,time.seconds,time.cents);
-    gateStart.disable_irq();
-    gateEnd.disable_irq();
-}
 
-void labyrinthLoop() {
-    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);
-}
 
 void configMode() {
     switch(mode) {
-        case LABYRINTH:
-            gateStart.enable_irq();
-            gateStart.rise(&start_time);
-            gateEnd.enable_irq();
-            gateEnd.rise(&stop_time);
-            loopMethod = &labyrinthLoop;
-            lcd.cls();
-            lcd.locate(0,0);
-            lcd.printf("Mode: LABYRINTH ");
-            wait(1);
-            break;
         
         case SPEED:
         default:
             gateStart.enable_irq();
             gateStart.rise(&measure_time);
-            gateEnd.disable_irq();
             loopMethod = &speedLoop;
             lcd.cls();
             lcd.locate(0,0);
@@ -281,7 +255,7 @@
 }
 
 void switchMode() {
-    mode = mode == SPEED ? LABYRINTH : SPEED;
+    mode = SPEED;
     reset_measure(); 
 }
 
@@ -297,7 +271,9 @@
     user_button.fall(&switchMode);
 
     gateStart.mode(PullDown);
-    gateEnd.mode(PullDown);
+
+    IRLED.period(1.0/38000.0);
+    IRLED = 0.5; 
 
     reset_measure();
 
@@ -309,9 +285,6 @@
         if (key != '\0') {
             if (!isRunning) {
                 if(key == 'A') {
-                    mode = LABYRINTH;
-                    reset_measure();
-                } else if(key == 'B') {
                     mode = SPEED;
                     reset_measure();
                 }