Demo of the sample LCD class, BMP280 Sensor and network with power on self test. Requires a network connectionb

Dependencies:   BMP280 TextLCD BME280

Revision:
1:e1cf7663f5ff
Parent:
0:36e89e3ed7c4
Child:
2:40403785b690
--- a/main.cpp	Wed Sep 13 11:03:52 2017 +0000
+++ b/main.cpp	Wed Dec 06 15:59:28 2017 +0000
@@ -1,5 +1,8 @@
 #include "mbed.h"
 #include "TextLCD.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+#include "sample_hardware.hpp"
 
 //#define BME
 #ifdef BME
@@ -13,23 +16,62 @@
 //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
+ 
+int main() {
+    //Greeting
+    lcd.printf("Testing\n\n");    
+    
+    //Power on self test
+    post();
+    
+    //Initialise the SD card
+    if ( sd.init() != 0) {
+        printf("Init failed \n");
+        errorCode(FATAL);
+    } 
+    
+    //Create a filing system for SD Card
+    FATFileSystem fs("sd", &sd);     
 
-//Sensor driver
-#ifdef BME
-BME280 sensor(D14, D15);
-#else
-BMP280 sensor(D14, D15);
-#endif
-
-int main() {
-        
-    while(1) {
+    //Open to WRITE
+    FILE* fp = fopen("/sd/test.csv","a");
+    if (fp == NULL) {
+        error("Could not open file for write\n");
+        errorCode(FATAL);
+    }
+            
+    //Press either switch to unmount
+    while ((SW1 == 0) && (SW2 == 0)) {
         double temp = sensor.getTemperature();
         double pressure = sensor.getPressure();
         lcd.printf("Temp   Pressure\n"); 
         lcd.printf("%6.1f ",temp);
         lcd.printf("%.2f\n",pressure);
-        wait(2.0);
+        
+        //Write to SD
+        fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
+        
+        wait(1.0);
+    }
+    
+    //Close File
+    fclose(fp);
+    
+    //Close down
+    sd.deinit();
+    printf("Unmounted...\n");
+    lcd.cls();
+    lcd.printf("Unmounted...\n\n");
+    
+    //Flash to indicate goodness
+    while(true) {
+        greenLED = 1;
+        wait(0.5);
+        greenLED = 0;
+        wait(0.1);    
     }
 }
 
+
+