-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSensorPressure.cpp
executable file
·53 lines (43 loc) · 1.61 KB
/
SensorPressure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "SensorPressure.h"
//Initialize
SensorPressure::SensorPressure()
{
}
//-------------------------------- Begin Pressure sensor --------------------------------------
void SensorPressure::begin()
{
SPI.begin();
#ifdef USE_MPL3115A2
mpl31.begin();
mpl31.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa
//mpl31.setOversampleRate(7); // Set Oversample to the recommended 128
mpl31.setOversampleRate(128); // Set Oversample to the recommended 128
mpl31.enableEventFlags(); // Enable all three pressure and temp event flags
mpl31.readTemp();
mpl31.readPressure();
//return 0;
#endif
}
//----------------------------------------------------------------------------------------------
//---------------------------------------- Get Pressure ----------------------------------------
float SensorPressure::getPressure()
{
#ifdef USE_MPL3115A2
mpl31.readTemp();
mpl31.readPressure();
return mpl31.readPressure();
#endif
}
//----------------------------------------------------------------------------------------------
//----------------------------------- Get Pressure (Pascal) ------------------------------------
float SensorPressure::getPressurePa()
{
return getPressure();
}
//----------------------------------------------------------------------------------------------
//------------------------------- Get Pressure (kilo Pascal) -----------------------------------
float SensorPressure::getPressureKPa()
{
return (getPressure()/1000);
}
//----------------------------------------------------------------------------------------------