A system to help you ride your bike better than you do right now.
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed LSM9DS1_Library_cal
main.cpp
- Committer:
- kswanson31
- Date:
- 2016-12-02
- Revision:
- 2:d08643ff3c62
- Parent:
- 1:9d3f2e86392e
- Child:
- 3:26e0c0d7984f
File content as of revision 2:d08643ff3c62:
#include "mbed.h" #include "SDFileSystem.h" #include "uLCD_4DGL.h" DigitalOut myled(LED1); SDFileSystem sd(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); //mosi -> DI, miso <- DO, slck -> sclck, CS -> CS uLCD_4DGL lcd(PinName tx, PinName rx, PinName rst); float distance; float speed; float maxSpeed; time_t start = 1480719111; int main() { set_time(start); // Set RTC time // open the file for reading and appending records // recall last trip recall_trip(&fp); wait(10); lcd.cls(); // normal operation loop here while(true) { time_t current = time(NULL); // check current speed // check curret distance // check time so far // display this on the screen // check if braking, turning left or right // show that on the screen } // store this trip lcd.cls(); store_trip(&fp); // close the file at the end of the program fclose(fp); // end everything } void store_trip(FILE * fp) { FILE *fp = fopen("/sd/records/recent.txt", "w"); // write trip results to the SD card if (fp == NULL) { lcd.locate(0, 1); lcd.printf("Could not open file for write\n"); } else { fprintf(fp, "%d %d %d", } } void recall_trip(FILE * fp) { // display the most recent trip made on the screen // display the most impressive trip (longest distance, best speed, least time) int lineCount; char str[12]; char split; // read out the most recent trip FILE *fp = fopen("/sd/records/recent.txt", "r"); if (fp == NULL) { lcd.locate(0, 1); lcd.printf("Could not open file for write\n"); } else { std::getline(file, str); lcd.locate(0, 1); lcd.printf("Most recent trip\n%s", str); } // read out the most impressive trip so far FILE *fp = fopen("/sd/records/best_of.txt", "r"); if(fp == NULL) { lcd.locate(0, 1); lcd.printf("Could not open file for write\n"); } else { lcd.locate(0, 1); while (std::getline(file, str)) { } } }