92

Dependencies:   ADXL362 ATParser MPL3115A2 TSL2561 mbed

Fork of Lab91 by Fanbo Sun

Revision:
4:eb81ef9e1621
Parent:
2:c322c1331eaa
Child:
5:4a5b8c114486
--- a/main.cpp	Fri Mar 09 01:11:50 2018 +0000
+++ b/main.cpp	Thu Apr 05 14:43:37 2018 +0000
@@ -2,10 +2,14 @@
 #include "MPL3115A2.h"
 #include <string>
 #include <math.h>
+#include <ATParser.h>
+#include "BufferedSerial.h"
 
-Serial pc(SERIAL_TX, SERIAL_RX);
+//Serial pc(SERIAL_TX, SERIAL_RX);
 DigitalOut myled(LED1);
 DigitalOut powerpin(PA_8); // GPIO pin
+BufferedSerial pc(SERIAL_TX, SERIAL_RX);
+BufferedSerial device(PA_9, PA_10);
 
 // Selects SDA as I2C1_SDA on pin PB_7
 // Selects SCL on I2C1_SCL on pin PB_6
@@ -22,8 +26,14 @@
     myled = 0;
     char c;
     powerpin = 0;
+    ATParser at = ATParser(device, "\r\n", 256, 2000, false);
+    char buffer[100];
+    pc.baud(115200);
+    device.baud(115200);
     double alt1 = pressure_sensor.getAltitude(), alt2; // initial alt
-
+    
+    mpl3115_reg_print( 0, 0);
+    
     while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
     {
         wait(1);
@@ -31,22 +41,13 @@
     
     while(1)
     {
-        if(powerpin) // if the GPIO pin is pulled high
+        if(pc.getc() == 's') // if the GPIO pin is pulled high
         {
             myled != myled;
             //turn on and off led at 1Hz
             p=pressure_sensor.getPressure();
             t=pressure_sensor.getTemperature();
-            alt2=pressure_sensor.getAltitude();
-            v = (alt2 - alt1)/ 1.1;
-            // velocity is just distance / time
-            // we measured the time to be 1.1 seconds between readings
-            // this is as fast as it will go because of the library we were given
-            pc.printf("velocity = %f\n\r", v);
-            alt1 = alt2;
-            
-            pc.printf("%f %f\n\r", t, p);
-            cnt++;
+            at.send("Hello");
         }
         else
         {