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:
- 6:45a5043acc7e
- Parent:
- 5:436b39863099
- Child:
- 7:0d5396762696
--- a/main.cpp Mon Dec 05 00:42:57 2016 +0000 +++ b/main.cpp Mon Dec 05 01:13:48 2016 +0000 @@ -14,7 +14,10 @@ int lightState; -DigitalOut led(LED1); +DigitalOut leftBlinker(LED1); +DigitalOut rightBlinker(LED1); +DigitalOut brakeLight(LED1); +Timer blinkT; SDFileSystem sd(p11, p12, p13, p14, "sd"); //mosi -> DI, miso <- DO, slck -> sclck, CS -> CS uLCD_4DGL lcd(p28, p27, p29); @@ -47,6 +50,8 @@ hallSensor.fall(&pass); hallT.start(); // start the hall sensor timer + + int blinks; while(going) { @@ -66,7 +71,29 @@ lcd.printf("Time : %1.1f\n\n", (float)seconds / 3600); // light states code - // lightstates = get_state(); + lightState = get_state(); + + if (lightState == STOP) { + brakeLight = 1; + } else if (lightState == GO) { + brakeLight = 0; + } else { + blinkT.start(); + } + + if (blinks > 10) { + rightBlinker = 0; leftBlinker = 0; + blinks = 0; + } else { + blinkT.stop(); + rightBlinker = ((0.5 - blinkT.read() == 0) && lightState == RIGHT) ? ~rightBlinker : rightBlinker; + leftBlinker = ((0.5 - blinkT.read() == 0) && lightState == LEFT) ? ~leftBlinker : leftBlinker; + blinkT.reset(); + blinkT.start(); + blinks++; + } + + } // store this trip @@ -161,6 +188,10 @@ file.close(); } +int get_state(void) { + // +} + void pass(void) { // interrupt, performed when the hallsensor passes the magnet stopped = 0; // reset the global