Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BlackBox by
blackBox.cpp
00001 // BlackBox that saves the data when a pin interrupt is given 00002 // VEHICLE CRASH BLACKBOX 00003 00004 00005 #include "mbed.h" 00006 #include "TextLCD.h" 00007 00008 TextLCD lcd(p22, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7 00009 Serial ftdi(USBTX, USBRX); //defines serial port 00010 DigitalIn crash(p21); //crash sensor input (high/low); 00011 LocalFileSystem local("local"); // define local file system 00012 00013 BusOut myleds(LED1,LED2,LED3, LED4); // 00014 00015 AnalogIn adc1(p15); //ADC, speed sensor 00016 float speed=0; 00017 00018 int count=0; // button count 00019 struct tm t; // declaring RTC. current time will be stored here 00020 00021 00022 00023 int main() { 00024 lcd.printf("Welcome!\n"); 00025 //setting RTC and initializing RTC 00026 t.tm_year = 2015; // current year 00027 t.tm_mon = 7; // current month 00028 t.tm_mday = 7; // current day 00029 t.tm_hour = 15; // current hour 00030 t.tm_min = 16; // current minute 00031 t.tm_sec = 0; // current second 00032 t.tm_year = t.tm_year - 1900; // adjust for tm structure required values 00033 t.tm_mon = t.tm_mon - 1; 00034 set_time(mktime(&t)); // set the time 00035 00036 FILE* Logfile = fopen ("/local/log.txt","w"); 00037 fclose(Logfile); 00038 00039 00040 00041 while(1) 00042 { 00043 time_t seconds = time(NULL); 00044 if(crash.read()==0) // if the button is pressed (If crash happened) 00045 { 00046 while(crash.read()==0); // wait until release 00047 wait_ms(20); // button debounce time to avoid registering multiple inputs 00048 count++; // count up 00049 00050 speed=adc1*120; 00051 00052 ftdi.printf("Time: %s \rcount: %d \r\nSpeed: %f \r\n",ctime(&seconds),count, speed); // send data to terminal 00053 ftdi.printf("-------------------------- \r\n"); 00054 myleds=count; //display count on LED 00055 lcd.cls(); 00056 lcd.printf("Speed: %0.1f \n",speed); //display speed on LCD 00057 00058 00059 FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending 00060 00061 fprintf(Logfile, "Time: %s \rcount: %d \r\nSpeed: %f \r\n",ctime(&seconds),count, speed); // save data to log.txt file 00062 fprintf(Logfile, "-------------------------- \r\n"); 00063 fclose(Logfile); 00064 } 00065 else 00066 { 00067 myleds=0; 00068 wait(1); 00069 myleds=10; 00070 wait(1); 00071 } 00072 00073 } 00074 00075 }
Generated on Fri Jul 22 2022 16:12:30 by
1.7.2
