Keiarash Zoughi's Multi-Sensor for weather detection.

Dependencies:   BMP180 N5110 mbed

Revision:
9:5ebf44c85f77
Parent:
8:956a130ebdf5
Child:
10:d62ac368381c
--- a/main.cpp	Fri May 08 11:21:53 2015 +0000
+++ b/main.cpp	Fri May 08 15:54:39 2015 +0000
@@ -25,13 +25,22 @@
 PwmOut Redled(p24);
 
 //globals
-int selectedOption = 0;
+int selectedOption1 = 0;
 int buttonPressed = 0;
+int selectedOption2 = 0;
+int selectedOption3 = 0;
+int selectedOption4 = 0;
 
 //boundary conditions - screen
 int cells[84][48];
 
-Timer t;
+Timer t1;
+Timer t2;
+Timer t3;
+Timer t4;
+Timer t5;
+Timer t6;
+
 
 void check()
 {
@@ -55,7 +64,6 @@
         lcd.printString(buffer,0,5);           // display on screen
 
 
-    float pressure = measurement.pressure;  // same idea with floats
 
     if(temperature > 30.0 ) {
 
@@ -82,11 +90,27 @@
 
 }
 
+void pie(){
+    lcd.clear();
+     // example of how to draw circles
+        
+        lcd.drawCircle(42,24,22,0);  // x,y,radius,transparent with outline
+
+
+        for (int x = 0; x < WIDTH ; x+=10) {
+            // x0,y0,x1,y1,type 0-white,1-black,2-dotted
+            lcd.drawLine(42,24,62,14,1);
+            lcd.drawLine(42,24,62,34,1);
 
 
 
 
 
+}
+wait(5);
+
+lcd.clear();
+}
 
 
 
@@ -123,8 +147,8 @@
     lcd.clear();
 
     Measurement measurement;  // measurement structure declared in BMP180 class
-    t.start();
-    while(t.read()<10) {
+    t1.start();
+    while(t1.read()<5) {
 
         // read values (T in Celsius and P in mb) and print over serial port
         measurement = bmp180.readValues();
@@ -140,8 +164,9 @@
             lcd.printString(buffer,0,1);           //
 
     }
-t.stop();
+t1.stop();
 lcd.clear();
+
 }
 
 void pressure()
@@ -150,9 +175,9 @@
 
     Measurement measurement;  // measurement structure declared in BMP180 class
     
-    t.start();
+    t2.start();
 
-    while(t.read()<10) {
+    while(t2.read()<5) {
 
         // read values (T in Celsius and P in mb) and print over serial port
         measurement = bmp180.readValues();
@@ -168,7 +193,7 @@
         if (length <= 14)
             lcd.printString(buffer,0,1);
     }
-t.stop();
+t2.stop();
 lcd.clear();
 
 }
@@ -183,9 +208,9 @@
     Measurement measurement;  // measurement structure declared in BMP180 class
 
 
-t.start();
+t3.start();
 
-    while(t.read()<10) {
+    while(t3.read()<5) {
         // read values (T in Celsius and P in mb) and print over serial port
         measurement = bmp180.readValues();
         char buffer[14];
@@ -200,10 +225,15 @@
             lcd.printString(buffer,0,1);           // display on screen
 
 
+            lcd.drawLine(4,48,24,28,1);
+            lcd.drawLine(24,28,44,48,1);
+            lcd.drawLine(34,38,44,28,1);
+            lcd.drawLine(44,28,64,48,1);
+            
 
 
     }
-t.stop();
+t3.stop();
 lcd.clear();
 
 }
@@ -219,8 +249,8 @@
     float graph[84]= {0};
     
     
-   t.start(); 
-    while(t.read()<15) {
+   t4.start(); 
+    while(t4.read()<15) {
 
         // read values (T in Celsius and P in mb) and print over serial port
         measurement = bmp180.readValues();
@@ -249,7 +279,7 @@
         }
     }
 
-t.stop();
+t4.stop();
 
 lcd.clear();
 }
@@ -263,7 +293,7 @@
     lcd.printString("Hold button!",6,2);//select measure menu
     wait(1);
     lcd.clear();
-    selectedOption = 0;
+    selectedOption1 = 0;
 
     while(1) {
 
@@ -275,7 +305,7 @@
         lcd.printString("go back",1,5);
 
         lcd.printString(">",62,1);
-        selectedOption = 1;
+        selectedOption1 = 1;
         if (pushbutton1)
             break;
         wait(2);
@@ -289,7 +319,7 @@
 
         lcd.printString("go back",1,5);
         lcd.printString(">",62,3);
-        selectedOption = 2;
+        selectedOption1 = 2;
         if (pushbutton1)
             break;
         wait(2);
@@ -302,7 +332,7 @@
         lcd.printString("pie chart",1,3);
         lcd.printString("go back",1,5);
         lcd.printString(">",62,5);
-        selectedOption = 3;
+        selectedOption1 = 3;
         if (pushbutton1)
             break;
         wait(2);
@@ -310,20 +340,20 @@
 
     }
 
-    if(selectedOption == 1) {
+    if(selectedOption1 == 1) {
 
         lcd.clear();
     }
 
-    if(selectedOption == 2) {
+    if(selectedOption1 == 2) {
 
         graph();
 
     }
 
-    if(selectedOption == 3) {
+    if(selectedOption1 == 3) {
 
-        graph();
+        pie();
     }
 
 
@@ -337,7 +367,7 @@
     lcd.printString("Hold button!",6,2);//select measure menu
     wait(1);
     lcd.clear();
-    selectedOption = 0;
+    selectedOption2 = 0;
 
     while(1) {
 
@@ -349,7 +379,7 @@
         lcd.printString("pressure",1,5);
 
         lcd.printString(">",62,1);
-        selectedOption = 1;
+        selectedOption2 = 1;
         if (pushbutton1)
             break;
         wait(2);
@@ -363,7 +393,7 @@
 
         lcd.printString("altitude",1,3);
         lcd.printString(">",62,3);
-        selectedOption = 2;
+        selectedOption2 = 2;
         if (pushbutton1)
             break;
         wait(2);
@@ -376,7 +406,7 @@
         lcd.printString("altitude",1,3);
         lcd.printString("pressure",1,5);
         lcd.printString(">",62,5);
-        selectedOption = 3;
+        selectedOption2 = 3;
         if (pushbutton1)
             break;
         wait(2);
@@ -384,18 +414,18 @@
 
     }
 
-    if(selectedOption == 1) {
+    if(selectedOption2 == 1) {
 
         pressure();
     }
 
-    if(selectedOption == 2) {
+    if(selectedOption2 == 2) {
 
         temperature();
 
     }
 
-    if(selectedOption == 3) {
+    if(selectedOption2 == 3) {
 
         altitude();
     }
@@ -421,7 +451,7 @@
     lcd.printString("Hold Button!",6,2);//select measure menu
     wait(1);
     lcd.clear();
-    selectedOption = 0;
+    selectedOption3 = 0;
 
     while(1) {
 
@@ -430,7 +460,7 @@
 
         lcd.printString("check",1,1);
         lcd.printString(">",62,1);
-        selectedOption = 1;
+        selectedOption3 = 1;
         if (pushbutton1)
             break;
         wait(2);
@@ -440,7 +470,7 @@
         lcd.drawRect(70,21,10,10,1);
         lcd.printString("go back",1,3);
         lcd.printString(">",62,3);
-        selectedOption = 2;
+        selectedOption3 = 2;
         if (pushbutton1)
             break;
         wait(2);
@@ -448,17 +478,15 @@
 
     }
 
-    if(selectedOption == 1) {
+    if(selectedOption3 == 1) {
 
         lcd.clear();
     }
 
-    if(selectedOption == 2) {
+    if(selectedOption3 == 2) {
 
         check();
-        leds = 15;
         wait(0.5);
-        leds = 0;
 
     }
 }
@@ -473,7 +501,7 @@
     wait(1);
     lcd.clear();
 
-    selectedOption = 0;
+    selectedOption4 = 0;
 
     while(1) {//initialse pushbutton as 0
 
@@ -487,7 +515,7 @@
         lcd.printString("graph",1,3);//select settings menu
         lcd.printString("measure",1,5);//select grpah plot
         lcd.printString(">",62,1);//pointer
-        selectedOption = 1;
+        selectedOption4 = 1;
         if (pushbutton1)
             break;
 
@@ -503,7 +531,7 @@
         lcd.printString("graph",1,3);
         lcd.printString("measure",1,5);
         lcd.printString(">",62,3);
-        selectedOption = 2;
+        selectedOption4 = 2;
         if (pushbutton1)
             break;
 
@@ -520,7 +548,7 @@
         lcd.printString("graph",1,3);
         lcd.printString("measure",1,5);
         lcd.printString(">",62,5);
-        selectedOption = 3;
+        selectedOption4 = 3;
         if (pushbutton1)
             break;
 
@@ -531,17 +559,17 @@
 
     }
 
-    if(selectedOption == 1) {
+    if(selectedOption4 == 1) {
 
         measurementsScreen();
     }
 
-    if(selectedOption == 2) {
+    if(selectedOption4 == 2) {
 
         extrasScreen();
     }
 
-    if(selectedOption == 3) {
+    if(selectedOption4 == 3) {
 
         graphScreen();
     }
@@ -560,7 +588,7 @@
 //main loop
 int main()
 {
-    pushbutton1.mode(PullUp);//initial value 0
+   pushbutton1.mode(PullUp);//initial value 0
     // initiliase barometer
     bmp180.init();
 
@@ -568,15 +596,15 @@
     introScreen();
     wait(3);
     Redled =0;
-    lcd.clear();
-    mainScreen();
+    
 
-    while(1) {
-        lcd.printString("main menu...",1,2);
-        wait(2);
-
-        mainScreen();
-
+   while(1) {
+   
+    lcd.clear();
+    lcd.printString("main menu...",1,2);
+    wait(2);
+    mainScreen();
+    
 
 
     }