Keiarash Zoughi's Multi-Sensor for weather detection.

Dependencies:   BMP180 N5110 mbed

Revision:
1:dea8267d47d6
Parent:
0:771a5148e8e7
Child:
2:635c58eb70fb
--- a/main.cpp	Sun May 03 06:47:12 2015 +0000
+++ b/main.cpp	Sun May 03 06:48:21 2015 +0000
@@ -3,41 +3,24 @@
 #include "BMP180.h"
 
 #define PI 3.14159265359
-
-//LCD inputs
-N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
-
-//serial port for debugging
-Serial serial(USBTX,USBRX);
-
-//LED outputs
+//
+AnalogOut aout(p18);  // DAC on pin 18
 BusOut leds(LED4,LED3,LED2,LED1);  // LEDs for display
 
-//speaker output
-AnalogOut aout(p18);  // DAC on pin 18
-
-//select button
+N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
+int cells[84][48];
+PwmOut Redled(p24);
 DigitalIn pushbutton1(p19);
-
-//???
-AnalogIn ain(p20);// float value or....
-
-//barometer sensor input
 BMP180 bmp180(p28,p27);   // SDA, SCL
-
-//warning LED
-PwmOut Redled(p24);
-
-//globals
+Serial serial(USBTX,USBRX);
+Serial pc(USBTX, USBRX); // Define serial TX RX
+AnalogIn ain(p20);
 int selectedOption = 0;
 int buttonPressed = 0;
 
-//boundary conditions - screen
-int cells[84][48];
-
-//shows pressure reading and temperature
 void measurement()
 {
+
     Measurement measurement;  // measurement structure declared in BMP180 class
     while(1) {
 
@@ -58,13 +41,16 @@
         length = sprintf(buffer,"P = %.2f mb",pressure);
         if (length <= 14)
             lcd.printString(buffer,0,2);
+
     }
 }
 
 
-//pushbutton - 0
+
+
 
-//plots graph of temperature point by point
+
+
 void graph()
 {
     Measurement measurement;  // measurement structure declared in BMP180 class
@@ -76,6 +62,9 @@
         measurement = bmp180.readValues();
         //serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
 
+
+
+
         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
@@ -98,46 +87,46 @@
             i=0;
             lcd.clear();
         }
+
     }
+
 }
 
-void settingScreen()
-{
+void settingScreen(){
     selectedOption = 0;
 
-    while(!pushbutton1) {
+while(!pushbutton1){
 
-        lcd.drawRect(70,6,10,10,1);
-        lcd.drawRect(70,21,10,10,0);
+lcd.drawRect(70,6,10,10,1);
+lcd.drawRect(70,21,10,10,0);
 
-        lcd.printString("clock",1,1);
-        lcd.printString(">",62,1);
-        selectedOption = 1;
+lcd.printString("clock",1,1);
+lcd.printString(">",62,1);
+selectedOption = 1;
 
         wait(2);
         lcd.clear();
 
-        lcd.drawRect(70,6,10,10,0);
-        lcd.drawRect(70,21,10,10,1);
-        lcd.printString("go back",1,3);
-        lcd.printString(">",62,3);
-        selectedOption = 2;
+lcd.drawRect(70,6,10,10,0);
+lcd.drawRect(70,21,10,10,1);
+lcd.printString("go back",1,3);
+lcd.printString(">",62,3);
+selectedOption = 2;
 
         wait(2);
         lcd.clear();
-
-    }
-
-    if(selectedOption == 1) {
+        
+  }
+  
+  if(selectedOption == 1){
+    
+    measurement();}
+    
+    if(selectedOption == 2){
+        
+        graph(); 
 
-        measurement();
-    }
-
-    if(selectedOption == 2) {
-
-        graph();
-
-    }
+}
 }
 
 void introScreen()
@@ -154,18 +143,17 @@
 {
     selectedOption = 0;
 
-    while(!pushbutton1) {//initialse pushbutton as 0
-        
-        //check boxes-options to be selected
-        lcd.drawRect(70,6,10,10,1);//check box 1
-        lcd.drawRect(70,21,10,10,0);//check box 2
-        lcd.drawRect(70,37,10,10,0);//check box 3
+    while(!pushbutton1) {
+
+        lcd.drawRect(70,6,10,10,1);
+        lcd.drawRect(70,21,10,10,0);
+        lcd.drawRect(70,37,10,10,0);
 
-        //option titles-appropriate to check boxes
-        lcd.printString("measure",1,1);//select measure menu
-        lcd.printString("settings",1,3);//select settings menu
-        lcd.printString("graph",1,5);//select grpah plot
-        lcd.printString(">",62,1);//pointer
+
+        lcd.printString("measure",1,1);
+        lcd.printString("settings",1,3);
+        lcd.printString("graph",1,5);
+        lcd.printString(">",62,1);
         selectedOption = 1;
 
         wait(2);
@@ -201,21 +189,19 @@
 
 
     }
-
-    if(selectedOption == 1) {
-
-        measurement();
-    }
-
-    if(selectedOption == 2) {
-
-        settingScreen();
-    }
-
-    if(selectedOption == 3) {
-
-        graph();
-    }
+    
+   if(selectedOption == 1){
+    
+    measurement();}
+    
+    if(selectedOption == 2){
+        
+        settingScreen();}
+        
+        if(selectedOption == 3){
+            
+          graph();    
+}
 }
 
 
@@ -227,47 +213,44 @@
 //void check(){
 
 // int temperature = measurement.temperature;
-
-
-// if(int temperature> 30; ){
+ 
+ 
+ // if(int temperature> 30; ){
 
-//   lcd.printString("temperature high!",1,1);
+  //   lcd.printString("temperature high!",1,1);
 
-//  Redled=1.0;
+ //  Redled=1.0;
 
 // wait(3); }
 
 // if(int temperature < 3;){
 
-//      lcd.printString("temperature low!",1,1);
+  //      lcd.printString("temperature low!",1,1);
 
-//   Redled= 1.0;
+   //   Redled= 1.0;
 
-//   wait(3); }
+ //   wait(3); }
 
 // }
 
 // void altitude(){
 
-//  float altitude = -(log(measurement.pressure/1013.25)*1.38*10^-23*measurement.temperature)/(9.81*28.95);
+  //  float altitude = -(log(measurement.pressure/1013.25)*1.38*10^-23*measurement.temperature)/(9.81*28.95);
 
 //}
 
 
 
-//main loop
+
 int main()
 {
-    pushbutton1.mode(PullDown);//initial value 0
+    pushbutton1.mode(PullDown);
     // initiliase barometer
     bmp180.init();
-    
     lcd.init();
     introScreen();
     wait(3);
     lcd.clear();
     mainScreen();
     
-    while(1) {
-    }
 }
\ No newline at end of file