A system to help you ride your bike better than you do right now.
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed LSM9DS1_Library_cal
Diff: main.cpp
- Revision:
- 10:8593877172d4
- Parent:
- 9:53bb4c706947
- Child:
- 11:f49250a7e4c3
--- a/main.cpp Mon Dec 05 03:16:36 2016 +0000 +++ b/main.cpp Mon Dec 05 05:11:21 2016 +0000 @@ -22,7 +22,7 @@ DigitalOut brakeLight(p21); Timer blinkT; -AnalogIn flex(p15); +AnalogIn flex(p20); LSM9DS1 imu(p9, p10, 0xD6, 0x3C); SDFileSystem sd(p11, p12, p13, p14, "sd"); //mosi -> DI, miso <- DO, slck -> sclck, CS -> CS @@ -48,10 +48,12 @@ int main() { // open the file for reading and appending records // recall last trip + lcd.cls(); recall_trips(); - wait(10); + wait(1); lcd.cls(); + imu.begin(); if (!imu.begin()) { lcd.printf("Failed to communicate with LSM9DS1.\n"); @@ -62,7 +64,7 @@ int going = 1; // cyclist is moving set_time(START_S); // Set RTC time - float theta; + float theta = 0; hallSensor.fall(&pass); hallT.start(); // start the hall sensor timer @@ -73,7 +75,7 @@ rightBlinker = 0; brakeLight = 0; - while(going) { + while(1) { seconds = time(NULL) - START_S; // return the seconds passed since start @@ -82,7 +84,7 @@ stopped = 1; } - going = (hallT.read() > 20.0 && stopped) ? 0 : 1; + going = (hallT.read() > 120.0 && stopped) ? 0 : 1; maxSpeed = (speed > maxSpeed) ? speed : maxSpeed; lcd.locate(0, 1); @@ -94,17 +96,18 @@ lcd.printf("Time : %3.1f min\n\n", (float)seconds / 60); lcd.circle(64, 128, 64, GREEN); + lcd.line(64, 128, 64 + 62*cos(theta), 128 - 62*sin(theta), BLACK); theta = PI - (speed / 9.536); - lcd.line(64, 128, 64 + 62*cos(theta), + 62*sin(theta), WHITE); + lcd.line(64, 128, 64 + 62*cos(theta), 128 - 62*sin(theta), WHITE); // light states code lightState = get_state(); - pc.printf("STATE %d\n", lightState); + pc.printf("STATE %d\n\r", lightState); if (lightState == STOP) { brakeLight = 1; - pc.printf("STOP FUCKER\n"); + pc.printf("STOP FUCKER\n\r"); } else if (lightState == GO) { brakeLight = 0; rightBlinker = 0; @@ -116,7 +119,7 @@ leftBlinker = 1; } } - + wait(1); } // store this trip @@ -220,7 +223,8 @@ imu.readAccel(); float f = flex.read(); int x = imu.ax, y = imu.ay, z = imu.az; - if (z > 0 && z > abs(y) && z > abs(x) && y < 0 && f >= 0.92) + 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) return LEFT;