![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Task 1,7,8 Working
Dependencies: BME280 BMP280 ELEC350-Coursework-2017 TextLCD
Fork of ELEC350-CWTEMPLATE-2017 by
Diff: main.cpp
- Revision:
- 3:a88838ff33e7
- Parent:
- 2:40403785b690
- Child:
- 5:2594b953f111
diff -r 40403785b690 -r a88838ff33e7 main.cpp --- a/main.cpp Wed Dec 06 17:00:37 2017 +0000 +++ b/main.cpp Thu Dec 07 15:29:33 2017 +0000 @@ -1,35 +1,25 @@ -#include "mbed.h" -#include "TextLCD.h" -#include "SDBlockDevice.h" -#include "FATFileSystem.h" #include "sample_hardware.hpp" - - +#include "Networkbits.hpp" -//#define BME -#ifdef BME -#include "BME280.h" -#else -#include "BMP280.h" -#endif +// This is a very short demo that demonstrates all the hardware used in the coursework. +// You will need a network connection set up (covered elsewhere). The host PC should have the address 10.0.0.1 -//LCD Driver -//RS D9 -//E D8 -//D7,6,4,2 are the 4 bit for d4-7 -TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7 -SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs +//Threads +Thread nwrkThread; + int main() { //Greeting - lcd.printf("Testing\n\n"); + printf("Testing\n\n"); //Power on self test post(); - //Initialise the SD card + //Initialise the SD card (this needs to move) if ( sd.init() != 0) { printf("Init failed \n"); + lcd.cls(); + lcd.printf("CANNOT INIT SD"); errorCode(FATAL); } @@ -40,21 +30,34 @@ FILE* fp = fopen("/sd/test.csv","a"); if (fp == NULL) { error("Could not open file for write\n"); + lcd.cls(); + lcd.printf("CANNOT OPEN FILE\n\n"); errorCode(FATAL); } - + + //Last message before sampling begins + lcd.cls(); + lcd.printf("READY\n\n"); + + //Press either switch to unmount while ((SW1 == 0) && (SW2 == 0)) { + + //Base loop delay + wait(1.0); + + //Read environmental sensors double temp = sensor.getTemperature(); double pressure = sensor.getPressure(); + + //Write new data to LCD (not fast!) + lcd.cls(); lcd.printf("Temp Pressure\n"); lcd.printf("%6.1f ",temp); lcd.printf("%.2f\n",pressure); - //Write to SD + //Write to SD (potentially slow) fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure); - - wait(1.0); } //Close File