11

Dependencies:   ADXL362 ATParser MPL3115A2 mbed

Fork of Lab7 by CPS-Lab*

main.cpp

Committer:
fanbsun
Date:
2018-03-02
Revision:
0:9a45e4f07b10
Child:
1:2630bf98c8fe
Child:
2:c322c1331eaa

File content as of revision 0:9a45e4f07b10:

#include "mbed.h"
#include "MPL3115A2.h"
#include "ADXL362.h"
#include <string>
#include <math.h>


ADXL362 ADXL362(PA_0,PA_7,PA_6,PA_1);
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
DigitalOut powerpin(PA_8);

// Selects SDA as I2C1_SDA on pin PB_7
// Selects SCL on I2C1_SCL on pin PB_6
// The I2C address of the pressure sensor is fixed at 0x60. 
MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);

int main() {
    int8_t a1, a2, a;
    double p, t;
    double v = 0.0;
    int cnt = 0;
    myled = 0;
    powerpin = 0;
    
    wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
    ADXL362.set_mode(ADXL362::MEASUREMENT);

    
    while(1)
    {
    if(powerpin)
    {
        myled = 1;
    a1=ADXL362.scanz_u8();
    p=pressure_sensor.getPressure();
    t=pressure_sensor.getTemperature();
    
    pc.printf("temp_%d = %f C ; pressure_%d = %f \n\r Pa",cnt,t,cnt,p);
    cnt++;
    
    wait_ms(100);
    a2=ADXL362.scanz_u8();
    a = a1 - a2;
    
    v = v + double(a) * 0.1;
    pc.printf(" velocity = %f \n\r",v);
    }
    else
    {
        myled = 0;
    }
}
}