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 TextLCD_HelloWorld by
blackBox.cpp
00001 // Hello World! for the TextLCD 00002 00003 #include "mbed.h" 00004 #include "TextLCD.h" 00005 00006 TextLCD lcd(p22, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7 00007 Serial ftdi(USBTX, USBRX); 00008 DigitalIn crash(p21); //crash sensor input (high/low); 00009 LocalFileSystem local("local"); // define local file system 00010 00011 BusOut myleds(LED1,LED2,LED3, LED4); // 00012 00013 AnalogIn adc1(p15); //ADC, speed sensor 00014 float speed=0; 00015 00016 int count=0; // button count 00017 struct tm t; // declaring RTC. current time will be stored here 00018 00019 00020 00021 int main() { 00022 lcd.printf("Welcome!\n"); 00023 //setting RTC and initializing RTC 00024 t.tm_year = 2015; // current year 00025 t.tm_mon = 7; // current month 00026 t.tm_mday = 7; // current day 00027 t.tm_hour = 15; // current hour 00028 t.tm_min = 16; // current minute 00029 t.tm_sec = 0; // current second 00030 t.tm_year = t.tm_year - 1900; // adjust for tm structure required values 00031 t.tm_mon = t.tm_mon - 1; 00032 set_time(mktime(&t)); // set the time 00033 00034 FILE* Logfile = fopen ("/local/log.txt","w"); 00035 fclose(Logfile); 00036 00037 00038 00039 while(1) 00040 { 00041 time_t seconds = time(NULL); 00042 if(crash.read()==0) // if the button is pressed 00043 { 00044 while(crash.read()==0); // wait until release 00045 wait_ms(20); // button debounce 00046 count++; // count up 00047 00048 speed=adc1*120; 00049 00050 ftdi.printf("Time: %s \rcount: %d \r\nSpeed: %f \r\n",ctime(&seconds),count, speed); // send data to terminal 00051 ftdi.printf("-------------------------- \r\n"); 00052 myleds=count; //display count on LED 00053 lcd.cls(); 00054 lcd.printf("Speed: %0.1f \n",speed); //display speed on LCD 00055 00056 00057 FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending 00058 00059 fprintf(Logfile, "Time: %s \rcount: %d \r\nSpeed: %f \r\n",ctime(&seconds),count, speed); // save data to log.txt file 00060 fprintf(Logfile, "-------------------------- \r\n"); 00061 fclose(Logfile); 00062 } 00063 else 00064 { 00065 myleds=0; 00066 wait(1); 00067 myleds=10; 00068 wait(1); 00069 } 00070 00071 } 00072 00073 }
Generated on Thu Jul 21 2022 08:07:01 by
1.7.2
