coursework

Revision:
1:dc648c5624b9
Child:
2:54c537a2569a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensor_data.h	Wed Jan 10 09:50:29 2018 +0000
@@ -0,0 +1,182 @@
+#include "mbed.h"
+#include "BMP280.h"
+#include "calender_operation.h"
+float getTemperature_bmp280; // Read the current Temperature  value  from BME280 sensor
+float getPressure_bmp280; // Read the current humidity value (humidity %) from BME280 sensor
+float fLDR;                // Read the current light intensity value from LDR sensor
+float temperature_data [120], pressure_data[120], LDR_data[120];
+BMP280 bmp280(D14,D15,0x77);  //Assigning the pin for BMP280 Pressure sensor
+ 
+AnalogIn LDR(A1);         //Assigning the pin for LDR 
+int counter_store = 0, full = 0, day, month, year, leap;
+ 
+//***** setting up the time ************
+// h/hh/mi/mni/s/ss
+//  h=> first integer value of the Hour 
+//  hh=> second integer value of the Hour 
+//  mi=> first integer value of the Minutes 
+//  mni=> second integer value of the Minutes 
+//  s=> first integer value of the Seconds
+//  ss => second integer value of the Seconds 
+void time_rule()
+{
+    if (ss == 10)
+    { 
+        ss = 0;
+        s++;
+    }
+    
+    if (s == 6 && ss == 1)
+    {
+        ss = 1;
+        s = 0;
+        mmi++;
+    }
+    
+    if (mmi == 10)
+    {
+        mmi = 0;
+        mi++;
+    }
+    
+    if (mi == 6 && mmi == 1)
+    {
+        mi = 0;
+        mmi = 1;
+        hh++;    
+    }
+    
+    if (hh == 10)
+    {
+        hh = 0;
+        h++;
+    }
+    
+    if(h == 2 && hh == 4)
+    {
+        h = 0;
+        hh = 0;
+        dd++;
+    }
+}
+ 
+/*********  Setting the date up *********/  
+void date_rule()
+{
+   if (mm == 10)
+    {
+        mm = 0;
+        m++;
+    }
+    
+    if (m == 1 && mm == 3)
+    {
+        m = 0;
+        mm = 1;
+        yyyy++;
+    }
+    
+    if (yyyy== 10)
+    {
+        yyyy = 0;
+        yyy++;
+    } 
+    if (yyy == 10)
+    {
+        yyy = 0;
+        yy++;
+    } 
+    if (yy == 10)
+    {
+        yy = 0;
+        y++;
+    } 
+    
+}
+ 
+ 
+void day_check()
+{
+    day = 10*d + dd;
+    month = mi*10+mmi;
+    year = y*1000+yy*100+yyy*10+yyyy;
+    if((month == 1)||(month ==3)||(month ==5)||(month ==7)||(month ==8)||(month ==10)||(month ==12))
+    {
+        if (day == 32)
+        {
+            mm++;
+            d = 0;
+            dd = 1;
+        } 
+    }
+ 
+    else if(month == 4||6||9||11 )
+    {
+        if (day == 31)
+        {
+            mm++;
+            d = 0;
+            dd = 1;
+        }
+    }
+    
+    else if(month == 2)
+    {
+        leap = year % 4;
+        if(leap == 0)
+        {
+            if (day == 30)
+            {
+                mm++;
+                d = 0;
+                dd = 1;
+            }
+        }
+        else 
+        {
+            if (day == 29)
+            {
+                mm++;
+                d = 0;
+                dd = 1;
+            }
+        }
+    }
+    date_rule();
+}
+ 
+ 
+ 
+//Sensor setup  
+void sensor_operation()
+{
+    getTemperature_bmp280 = bmp280.getTemperature();
+    
+    getPressure_bmp280 = bmp280.getPressure();    
+    fLDR = LDR;
+}
+//******* Displaying sensor data to the lcd to allocated position ************* 
+void sensor_lcd()
+{
+        lcd.locate(10,0);
+        lcd.printf("L:%1.2f", fLDR);
+        
+        lcd.locate(0,0);
+        lcd.printf("P:%3.1f", getPressure_bmp280);
+        
+        lcd.locate(10,1);
+        lcd.printf("T:%3.1f", getTemperature_bmp280);
+    }
+void records() 
+{  
+     temperature_data[counter_store] = getTemperature_bmp280;
+     pressure_data[counter_store] = getPressure_bmp280;
+     LDR_data[counter_store] = fLDR;
+     
+     if (counter_store == 120)
+     {
+         counter_store = 0;
+         full = 1;
+     }
+     counter_store++;
+}
\ No newline at end of file