-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSensorTemperature.cpp
executable file
·62 lines (51 loc) · 1.35 KB
/
SensorTemperature.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
54
55
56
57
58
59
60
61
62
#include "SensorTemperature.h"
//Initialize
SensorTemperature::SensorTemperature()
{
}
//------------------------------- Begin Temperature sensor -------------------------------------
int SensorTemperature::begin()
{
SPI.begin();
#ifdef USE_SI7021
if(si70.begin()!=0)
return 0;
else
return 1;
#endif
#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.enableEventFlags(); // Enable all three pressure and temp event flags
mpl31.readTemp();
mpl31.readPressure();
return 0;
#endif
#ifdef USE_AM2315
if(am23.begin())
{
delay(100);
return 0;
}
else
return 1;
#endif
}
//----------------------------------------------------------------------------------------------
//------------------------------------ Get Temperature ----------------------------------------
float SensorTemperature::getTemperature()
{
#ifdef USE_SI7021
return si70.getTemp();
#endif
#ifdef USE_MPL3115A2
return mpl31.readTemp();
#endif
#ifdef USE_AM2315
float temperature = am23.readTemperature();
delay(100);
return temperature;
#endif
}
//----------------------------------------------------------------------------------------------