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.
Dependencies: BMP180 N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 0:d78ac68077c6
- Child:
- 1:e60b9f116d38
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Apr 08 14:11:09 2015 +0000
@@ -0,0 +1,124 @@
+#include "mbed.h"
+#include "N5110.h"
+#include "BMP180.h"
+#include "PowerControl/PowerControl.h"
+#include "PowerControl/EthernetPowerControl.h"
+
+BMP180 bmp180(p28,p27); // SDA, SCL
+N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
+Serial serial(USBTX,USBRX);
+
+Ticker timer; //Create ticker object for temperature and pressure readings
+Ticker timer1; //Create ticker object for real time clock
+
+
+
+void serialISR(); // ISR that is called when serial data is received
+void setTime(); // function to set the UNIX time
+
+int setTimeFlag = 0; // flag for real time clock ISR
+int timerFlag = 0; // Flag for tempesrature pressure reading ISR
+int length;
+
+char bufferTime[14]; // buffer to store time
+char bufferDate[14]; //buffer to store date
+char bufferT[14];
+char bufferP[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
+// so can display a string of a maximum 14 characters in length
+// or create formatted strings - ensure they aren't more than 14 characters long
+
+
+
+
+
+void timer1Expired()
+{
+// set flagb
+ setTimeFlag = 1;
+}
+
+
+
+
+void setTime() // sets the time every second
+{
+
+ if (setTimeFlag) {
+ setTimeFlag=0;
+ time_t seconds = time(NULL); // get current time
+// format time into a string (time and date)
+ strftime(bufferTime, 14 , "%X", localtime(&seconds));
+ strftime(bufferDate, 14 , "%d/%m/%y", localtime(&seconds));
+ }
+}
+
+
+
+
+void timerExpired()
+{
+ timerFlag=1;
+}
+
+
+
+void readData()
+{
+
+ Measurement measurement; // measurement structure declared in BMP180 class
+
+ // read values (T in Celsius and P in mb) and print over serial port
+ measurement = bmp180.readValues();
+ // serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
+
+ int temperature = measurement.temperature;
+ length = sprintf(bufferT,"T = %0.1d C",temperature); // print formatted data to buffer
+ // it is important the format specifier ensures the length will fit in the buffer
+
+ float pressure = measurement.pressure; // same idea with floats
+ length = sprintf(bufferP,"P = %.2f mb",pressure);
+
+
+}
+
+
+void displayData()
+{
+ if (length <= 14) { // if string will fit on display
+ lcd.printString(bufferT,0,1); // display on screen
+ lcd.printString(bufferP,0,2);
+ lcd.printString(bufferTime,0,3);
+ lcd.printString(bufferDate,0,4);
+ }
+}
+
+
+void updateData()
+{
+ if (timerFlag) {
+ timerFlag=0;
+ readData();
+ displayData();
+ }
+ Sleep();
+}
+
+
+int main()
+{
+
+ // initiliase barometer
+ bmp180.init();
+ lcd.init();
+ timer.attach(&timerExpired,1.0);
+ timer1.attach(&timer1Expired,1.0);
+ set_time(0); // initialise time to 1st January 1970///// This is where we should set our time
+
+ while(1) {
+ setTime();
+ updateData();
+ }
+}
+
+
+