A system to help you ride your bike better than you do right now.

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed LSM9DS1_Library_cal

Revision:
11:f49250a7e4c3
Parent:
10:8593877172d4
--- a/main.cpp	Mon Dec 05 05:11:21 2016 +0000
+++ b/main.cpp	Sat Dec 10 04:30:02 2016 +0000
@@ -17,8 +17,8 @@
 
 int lightState;
 
-DigitalOut leftBlinker(p22);
-DigitalOut rightBlinker(p23);
+DigitalOut leftSignal(p22);
+DigitalOut rightSignal(p23);
 DigitalOut brakeLight(p21);
 Timer blinkT;
 
@@ -68,14 +68,12 @@
     
     hallSensor.fall(&pass);
     hallT.start();     // start the hall sensor timer
-    
-    int blinks;
-    
-    leftBlinker = 0;
-    rightBlinker = 0;
+        
+    leftSignal = 0;
+    rightSignal = 0;
     brakeLight = 0;
 
-    while(1) {
+    while(going) {
         
         seconds = time(NULL) - START_S; // return the seconds passed since start
         
@@ -84,7 +82,7 @@
             stopped = 1;
         }
 
-        going = (hallT.read() > 120.0 && stopped) ? 0 : 1;
+        going = (hallT.read() > 200.0 && stopped) ? 0 : 1;
         maxSpeed = (speed > maxSpeed) ? speed : maxSpeed;
         
         lcd.locate(0, 1);
@@ -107,16 +105,15 @@
         
         if (lightState == STOP) {
             brakeLight = 1;
-            pc.printf("STOP FUCKER\n\r");
         } else if (lightState == GO) {
             brakeLight = 0;
-            rightBlinker = 0;
-            leftBlinker = 0;
+            rightSignal = 0;
+            leftSignal = 0;
         } else {
             if (lightState == RIGHT) {
-                rightBlinker = 1;
+                rightSignal = 1;
             } else {
-                leftBlinker = 1;
+                leftSignal = 1;
             }
         }
         wait(1);
@@ -149,9 +146,9 @@
     } else {
         file >> f_miles >> f_maxSpeed >> f_minutes;
         lcd.locate(0, 1);
-        lcd.printf("Your last trip\n\n");
-        lcd.printf("Distance : %3.1f mi\n\n", f_miles);
-        lcd.printf("Top speed : %2.1f mph\n\n", f_maxSpeed);
+        lcd.printf("PRIOR TRIP\n\n");
+        lcd.printf("Dist : %3.1f mi\n\n", f_miles);
+        lcd.printf("High : %2.1f mph\n\n", f_maxSpeed);
         lcd.printf("Time : %3.1f min\n\n", f_minutes);
     }
     
@@ -167,9 +164,9 @@
     } else {
         // show the best trip
         file >> f_miles >> f_maxSpeed >> f_minutes;
-        lcd.printf("Your best trip\n\n");
-        lcd.printf("Distance : %3.1f mi\n\n", f_miles);
-        lcd.printf("Top speed : %2.1f mph\n\n", f_maxSpeed);
+        lcd.printf("BEST TRIP\n\n");
+        lcd.printf("Dist : %3.1f mi\n\n", f_miles);
+        lcd.printf("High : %2.1f mph\n\n", f_maxSpeed);
         lcd.printf("Time : %3.1f min\n\n", f_minutes);
     }
 
@@ -182,6 +179,9 @@
     // determine whether this trip was a record, and indicate if so
     
     float minutes;
+    float f_miles;
+    float f_maxSpeed;
+    float f_minutes;
     fstream file;
     
     file.open("/sd/records/recent.txt");
@@ -211,8 +211,13 @@
         lcd.locate(0, 1);
         lcd.printf("Could not open file\n");
     } else {
-        lcd.locate(0, 1);
+        // retrieve the previous record
+        file >> f_miles >> f_maxSpeed >> f_minutes;
         // check if you beat your best
+        if (miles >= f_miles && maxSpeed >= f_maxSpeed && minutes >= f_minutes) {
+            lcd.printf("A new record!");
+            file << fixed << setprecision(1) << miles << " " << maxSpeed << " " << minutes << endl;
+        }
     }
     
     file.close();
@@ -226,7 +231,8 @@
     pc.printf("x: %d, y: %d, z: %d, flex: %f\n\r", x,y,z,f);
     if (z > 0 && z > abs(y) && z > abs(x) && y < 0 && f >= 0.87)
         return STOP;
-    if (x < 0 && abs(x) > abs(z) && abs(x) > abs(y) && f <= 0.87)
+//    if (x < 0 && abs(x) > abs(z) && abs(x) > abs(y) && f <= 0.87)
+    if (x < 0 && abs(x) > abs(z) && abs(x) > abs(y))
         return LEFT;
     if (y > 0 && y > abs(z) && y > abs(x) && f >= 0.87)
         return RIGHT;