Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 0NicksCoursework_copywithserialtime by
Revision 5:9b4844128e09, committed 2018-01-05
- Comitter:
- liam_grazier
- Date:
- Fri Jan 05 14:13:43 2018 +0000
- Parent:
- 4:d26b261b76c9
- Child:
- 6:f0601ebd2423
- Commit message:
- nick cw start ...
Changed in this revision
--- a/BME280.lib Thu Dec 07 15:43:01 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/MACRUM/code/BME280/#c1f1647004c4
--- a/ELEC350-Coursework-2017.lib Thu Dec 07 15:43:01 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/teams/University-of-Plymouth-Stage-2-and-3/code/ELEC350-Coursework-2017/#df979097cc71
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LGLCD.lib Fri Jan 05 14:13:43 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/liam_grazier/code/LGLCD/#ef052de2d7d0
--- a/TextLCD.lib Thu Dec 07 15:43:01 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/components.cpp Fri Jan 05 14:13:43 2018 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "components.hpp"
+#include "lglcd.h"
+
+//#include "Networkbits.hpp"
+#define RED_DONE 1
+#define YELLOW_DONE 2
+
+//Digital outputs
+DigitalOut onBoardLED(LED1);
+DigitalOut redLED(PE_15);
+DigitalOut yellowLED(PB_10);
+DigitalOut greenLED(PB_11);
+
+//Inputs
+DigitalIn onBoardSwitch(USER_BUTTON);
+DigitalIn SW1(PE_12);
+DigitalIn SW2(PE_14);
+//Serial pc(USBTX, USBRX);
+AnalogIn adcIn(PA_0);
+
+//Environmental Sensor driver
+#ifdef BME
+BME280 sensor(D14, D15);
+#else
+BMP280 sensor(D14, D15);
+#endif
+lglcd mylcd(D7,D6,D5,D4,D3,D2);
+
+//POWER ON SELF TEST
+void post()
+{
+ //posttest
+}
+
+void errorCode(ELEC350_ERROR_CODE err)
+{
+ switch (err) {
+ case OK:
+ greenLED = 1;
+ wait(1.0);
+ greenLED = 0;
+ return;
+ case FATAL:
+ while(1) {
+ redLED = 1;
+ wait(0.1);
+ redLED = 0;
+ wait(0.1);
+ }
+ };
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/components.hpp Fri Jan 05 14:13:43 2018 +0000
@@ -0,0 +1,29 @@
+#ifndef __sample_hardware__
+#define __sample_hardware__
+
+//#define BME
+#ifdef BME
+#include "BME280.h"
+#else
+#include "BMP280.h"
+#endif
+
+
+enum ELEC350_ERROR_CODE {OK, FATAL};
+extern DigitalOut onBoardLED;
+extern DigitalOut redLED;
+extern DigitalOut yellowLED;
+extern DigitalOut greenLED;
+extern DigitalIn onBoardSwitch;
+extern DigitalIn SW1;
+extern DigitalIn SW2;
+//extern Serial pc;
+extern AnalogIn adcIn;
+#ifdef BME
+extern BME280 sensor;
+#else
+extern BMP280 sensor;
+#endif
+extern void post();
+extern void errorCode(ELEC350_ERROR_CODE err);
+#endif
\ No newline at end of file
Binary file img/uvision.png has changed
--- a/main.cpp Thu Dec 07 15:43:01 2017 +0000
+++ b/main.cpp Fri Jan 05 14:13:43 2018 +0000
@@ -1,81 +1,40 @@
-#include "sample_hardware.hpp"
-#include "Networkbits.hpp"
-
+#include "components.hpp"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+//#include "Networkbits.hpp"
+#include "mbed.h"
+#include "lglcd.h"
+#include "stdio.h"
// 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
//Threads
Thread nwrkThread;
-
-
-int main() {
- //Greeting
- printf("Testing\n\n");
-
- //Power on self test
- post();
-
- //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);
- }
-
- //Create a filing system for SD Card
- FATFileSystem fs("sd", &sd);
-
- //Open to WRITE
- 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);
+int main(){
+lglcd mylcd(D7,D6,D5,D4,D3,D2);
+mylcd.clear();
+while(true){
+double temp = sensor.getTemperature();
+double pressure = sensor.getPressure();
+char TEM[6];
+char PRE[5];
+sprintf(TEM,"%.2f", temp);
+sprintf(PRE,"%.2f", pressure);
+printf(TEM);
+printf(PRE);
+mylcd.clear();
+mylcd.write("Pre: ");
+mylcd.write(PRE);
+wait(0.5);
+mylcd.clear();
+mylcd.write("Temp: ");
+mylcd.write(TEM);
+wait(0.5);
+
}
- //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 (potentially slow)
- fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
- }
-
- //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);
- }
+
}
