Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
amrita_arm19
Date:
Thu Mar 31 10:21:27 2016 +0000
Parent:
6:5fcb9eb2a1f1
Commit message:
Blackbox working;

Changed in this revision

blackBox.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
diff -r 5fcb9eb2a1f1 -r 69f13b0c0cc2 blackBox.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blackBox.cpp	Thu Mar 31 10:21:27 2016 +0000
@@ -0,0 +1,73 @@
+// Hello World! for the TextLCD
+
+#include "mbed.h"
+#include "TextLCD.h"
+
+TextLCD lcd(p22, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7
+Serial ftdi(USBTX, USBRX);
+DigitalIn crash(p21); //crash sensor input (high/low);
+LocalFileSystem local("local");      // define local file system
+
+BusOut myleds(LED1,LED2,LED3, LED4);  //
+
+AnalogIn adc1(p15);  //ADC, speed sensor
+float speed=0;
+
+int count=0;                         // button count 
+struct tm t;                         // declaring RTC. current time will be stored here
+
+
+
+int main() {
+    lcd.printf("Welcome!\n");
+    //setting RTC and initializing RTC
+    t.tm_year = 2015;     // current year
+    t.tm_mon = 7;         // current month
+    t.tm_mday = 7;        // current day
+    t.tm_hour = 15;       // current hour
+    t.tm_min = 16;        // current minute
+    t.tm_sec = 0;         // current second   
+    t.tm_year = t.tm_year - 1900;   // adjust for tm structure required values
+    t.tm_mon = t.tm_mon - 1;
+    set_time(mktime(&t));           // set the time
+    
+    FILE* Logfile = fopen ("/local/log.txt","w");
+    fclose(Logfile);
+    
+    
+        
+    while(1) 
+    {
+        time_t seconds = time(NULL);
+        if(crash.read()==0)          // if the button is pressed
+        {   
+            while(crash.read()==0);  // wait until release
+            wait_ms(20);              // button debounce
+            count++;                  // count up
+            
+            speed=adc1*120;
+            
+            ftdi.printf("Time: %s \rcount: %d \r\nSpeed: %f \r\n",ctime(&seconds),count, speed);         // send data to terminal
+            ftdi.printf("-------------------------- \r\n");
+            myleds=count; //display count on LED
+            lcd.cls();
+            lcd.printf("Speed: %0.1f \n",speed); //display speed on LCD
+            
+            
+            FILE* Logfile = fopen ("/local/log.txt","a");                                  // open file for appending  
+            
+            fprintf(Logfile, "Time: %s \rcount: %d \r\nSpeed: %f \r\n",ctime(&seconds),count, speed);    // save data to log.txt file
+            fprintf(Logfile, "-------------------------- \r\n");
+            fclose(Logfile);  
+            }
+            else
+            {
+                myleds=0;
+                wait(1);
+                myleds=10;
+                wait(1);
+                }
+                
+         }  
+    
+}
diff -r 5fcb9eb2a1f1 -r 69f13b0c0cc2 main.cpp
--- a/main.cpp	Thu Mar 31 05:15:45 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-// Hello World! for the TextLCD
-
-#include "mbed.h"
-#include "TextLCD.h"
-
-TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7
-Serial ftdi(USBTX, USBRX);
-/*
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-*/
-BusOut myleds(LED1,LED2,LED3, LED4);
-
-int time1=0;                         // button count 
-
-
-
-int main() {
-    lcd.printf("Welcome!\n");
-    ftdi.printf("Enter LED on time: ");
-    ftdi.scanf("%d", &time1);
-    ftdi.printf(":%d\n\r", time1);   
-    
-    
-    while(1) 
-    {  
-    if(!ftdi.readable())
-    {
-        lcd.printf("LED on: %d\n", time1);
-        
-        myleds=15;
-        /*
-        led1=1;
-        led2=1;
-        led3=1;
-        led4=1;
-        */
-        wait(time1);
-        myleds=10;
-        /*led1=0;
-        led2=0;
-        led3=0;
-        led4=0;
-        */
-        wait(time1);
-        }
-        
-        else if(ftdi.readable())
-        {
-            int a;
-            ftdi.scanf("%d", &a);
-            time1=a;
-            ftdi.printf("New time: %d\n\r", time1);
-            
-            lcd.cls();
-            /*
-            _rs=0;
-            _d = 0x01;
-            wait(0.000040f); // most instructions take 40us
-            _e = 0;
-            wait(0.000040f);
-            _e = 1;
-            */
-
-            lcd.printf("LED on (new): %d\n\n", time1);
-            }
-            }           
-    
-}