Program to display temperature and pressure readings along with date and time.
Dependencies: BMP180 N5110 PowerControl mbed
main.cpp
- Committer:
- el13akr
- Date:
- 2015-04-29
- Revision:
- 1:026d80a2f7a9
- Parent:
- 0:c2a88630fb72
- Child:
- 2:63ef0a1afcbe
File content as of revision 1:026d80a2f7a9:
#include "mbed.h" #include "N5110.h" #include "BMP180.h" // VCC,SCE,RST,D/C,MOSI,SCLK,LED N5110 lcd(p7,p8,p9,p10,p11,p13,p26); // Can also power (VCC) directly from VOUT (3.3 V) - // Can give better performance due to current limitation from GPIO pin Ticker timer ; //create a ticker object to read the data from the sensor Timeout timeOut ; BMP180 bmp180(p28,p27); Serial serial(USBTX,USBRX); AnalogIn POT(p20); int timerFlag= 0; int timeOutFlag = 0 ; int temperature ; float pressure; void screen() { lcd.printString("Weather Logger",0,2); lcd.printString("3000",32,3); lcd.printString("Alex Raper",15,5); lcd.refresh(); } void menu() { lcd.clear(); if (POT>(1.0/2.0)) { lcd.printString("Temperature",2,2); lcd.printString(">",76,2); lcd.printString("Graph",0,5); lcd.printString("Current",42,5); } else { lcd.printString("Pressure",18,2); lcd.printString("<",2,2); lcd.printString("Graph",0,5); lcd.printString("Current",42,5); } } void timerExpired(){ timerFlag = 1 ; } void timeOutStopped(){ timeOutFlag = 1; } void recieveData() { 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); temperature = measurement.temperature ; pressure = measurement.pressure ; } void displayData() { char buffer[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 int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer // it is important the format specifier ensures the length will fit in the buffer if (length <= 14) // if string will fit on display lcd.printString(buffer,0,1); // display on screen length = sprintf(buffer,"P = %.2f mb",pressure); if (length <= 14) lcd.printString(buffer,0,2); } int main() { // first need to initialise display lcd.init(); // initiliase barometer bmp180.init(); timer.attach (&timerExpired , 1.0); timeOut.attach (&timeOutStopped , 2.0); screen(); while(1) { if (timeOutFlag ==1 ){ menu(); // if (timerFlag ==1){ // timerFlag = 0; // lcd.clear(); // recieveData(); // displayData(); // // menu(); // } } } }