sensor
Dependencies: BMP280 ELEC350-Practicals-FZ429 BME280
main.cpp@6:2423aac599cd, 2018-11-30 (annotated)
- Committer:
- Joelpallent
- Date:
- Fri Nov 30 13:13:55 2018 +0000
- Revision:
- 6:2423aac599cd
- Parent:
- 5:e24f1e549da1
sensor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martinsimpson | 0:1ce5a958aaf8 | 1 | /* Access an SD Card using SPI */ |
martinsimpson | 0:1ce5a958aaf8 | 2 | |
martinsimpson | 0:1ce5a958aaf8 | 3 | #include "mbed.h" |
Joelpallent | 5:e24f1e549da1 | 4 | //#include "SDBlockDevice.h" |
martinsimpson | 0:1ce5a958aaf8 | 5 | #include "FATFileSystem.h" |
noutram | 2:fad34c30dcc4 | 6 | #include "sample_hardware.hpp" |
noutram | 4:17fe5b63cd8a | 7 | #include "mbed_events.h" |
Joelpallent | 5:e24f1e549da1 | 8 | #define _DEBUG |
Joelpallent | 5:e24f1e549da1 | 9 | |
Joelpallent | 5:e24f1e549da1 | 10 | |
Joelpallent | 5:e24f1e549da1 | 11 | #include "BMP280.h" |
Joelpallent | 5:e24f1e549da1 | 12 | |
Joelpallent | 5:e24f1e549da1 | 13 | #define _DEBUG |
martinsimpson | 0:1ce5a958aaf8 | 14 | |
noutram | 2:fad34c30dcc4 | 15 | //SD Card Object |
Joelpallent | 5:e24f1e549da1 | 16 | //SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs |
noutram | 4:17fe5b63cd8a | 17 | |
noutram | 4:17fe5b63cd8a | 18 | //Event queue for main |
noutram | 4:17fe5b63cd8a | 19 | EventQueue queue; |
noutram | 4:17fe5b63cd8a | 20 | |
noutram | 4:17fe5b63cd8a | 21 | //File pointer for the SD card |
noutram | 4:17fe5b63cd8a | 22 | FILE* fp; |
noutram | 4:17fe5b63cd8a | 23 | |
noutram | 4:17fe5b63cd8a | 24 | //Flag to indicate if the user has ejected the SD card |
Joelpallent | 5:e24f1e549da1 | 25 | //bool ejected = false; |
martinsimpson | 0:1ce5a958aaf8 | 26 | |
noutram | 4:17fe5b63cd8a | 27 | //This is called every 5 seconds by the main event queue (main thread) |
noutram | 4:17fe5b63cd8a | 28 | void takeSample() |
noutram | 4:17fe5b63cd8a | 29 | { |
noutram | 4:17fe5b63cd8a | 30 | //If the card is unmounted, just return |
Joelpallent | 5:e24f1e549da1 | 31 | // if (ejected == true) { |
Joelpallent | 5:e24f1e549da1 | 32 | // return; |
Joelpallent | 5:e24f1e549da1 | 33 | // } |
noutram | 4:17fe5b63cd8a | 34 | |
noutram | 4:17fe5b63cd8a | 35 | //Read Sensors (I2C) |
noutram | 4:17fe5b63cd8a | 36 | float temp = sensor.getTemperature(); |
noutram | 4:17fe5b63cd8a | 37 | float pressure = sensor.getPressure(); |
noutram | 4:17fe5b63cd8a | 38 | |
noutram | 4:17fe5b63cd8a | 39 | //Write to SD Card |
Joelpallent | 5:e24f1e549da1 | 40 | // fprintf(fp, "%f,%f\n", temp, pressure); |
noutram | 4:17fe5b63cd8a | 41 | |
noutram | 4:17fe5b63cd8a | 42 | //Flash to indicate the sampling is alive |
noutram | 4:17fe5b63cd8a | 43 | redLED = 1; |
noutram | 4:17fe5b63cd8a | 44 | Thread::wait(100); |
noutram | 4:17fe5b63cd8a | 45 | redLED = 0; |
noutram | 4:17fe5b63cd8a | 46 | |
Joelpallent | 5:e24f1e549da1 | 47 | |
noutram | 4:17fe5b63cd8a | 48 | } |
noutram | 4:17fe5b63cd8a | 49 | |
martinsimpson | 0:1ce5a958aaf8 | 50 | int main() |
martinsimpson | 0:1ce5a958aaf8 | 51 | { |
noutram | 2:fad34c30dcc4 | 52 | //POWER ON SELF TEST |
noutram | 2:fad34c30dcc4 | 53 | post(); |
noutram | 2:fad34c30dcc4 | 54 | |
Joelpallent | 5:e24f1e549da1 | 55 | // printf("Initialise\n\r\r"); |
Joelpallent | 5:e24f1e549da1 | 56 | |
Joelpallent | 5:e24f1e549da1 | 57 | |
martinsimpson | 0:1ce5a958aaf8 | 58 | |
Joelpallent | 5:e24f1e549da1 | 59 | |
Joelpallent | 5:e24f1e549da1 | 60 | while(1) |
Joelpallent | 5:e24f1e549da1 | 61 | { |
Joelpallent | 5:e24f1e549da1 | 62 | Thread::wait(5000); |
Joelpallent | 5:e24f1e549da1 | 63 | post(); |
martinsimpson | 0:1ce5a958aaf8 | 64 | } |
martinsimpson | 0:1ce5a958aaf8 | 65 | |
Joelpallent | 5:e24f1e549da1 | 66 | |
Joelpallent | 5:e24f1e549da1 | 67 | } |
martinsimpson | 0:1ce5a958aaf8 | 68 | |
martinsimpson | 0:1ce5a958aaf8 | 69 | |
Joelpallent | 5:e24f1e549da1 | 70 |