Final Version

Dependencies:   C12832 LM75B PWM_Tone_Library mbed Grove_Air_Quality_Sensor_Library

Files at this revision

API Documentation at this revision

Comitter:
Fleishmachine
Date:
Wed Apr 19 09:10:58 2017 +0000
Parent:
6:6ae884c9757a
Child:
8:458213f22315
Commit message:
19/04/2017

Changed in this revision

Grove_Air_Quality_Sensor_Library.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Grove_Air_Quality_Sensor_Library.lib	Wed Apr 19 09:10:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbedAustin/code/Grove_Air_Quality_Sensor_Library/#885417624ec2
--- a/main.cpp	Wed Mar 15 11:12:37 2017 +0000
+++ b/main.cpp	Wed Apr 19 09:10:58 2017 +0000
@@ -1,9 +1,12 @@
 #include "mbed.h"
 #include "pwm_tone.h"
 #include "C12832.h"
-Serial pc(USBTX, USBRX);
+
+// Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10
+Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer
 PwmOut Buzzer(D5);
 C12832 lcd (p5, p7, p6, p8, p11);
+AnalogIn air(p20);
 AnalogIn sensor(p17);
 PwmOut spkr(p26);
 PwmOut r (p23); // red light
@@ -13,7 +16,7 @@
 PwmOut Ctrl1(p21); //relay
 PwmOut Ctrl2(p22); //relay
 
-BusOut leds(LED1,LED2,LED3,LED4); // blue LEDs that we can still use  
+BusOut leds(LED1); // blue LED1 when air quality is low
 
 
 
@@ -22,48 +25,9 @@
 BusIn Left(p13);
 BusIn Right(p16);
 
-/* float C_3 = 1000000/Do3,  // can we erease it??
-       Cs_3 = 1000000/Do3s,
-       D_3 = 1000000/Re3,
-       Ds_3 = 1000000/Re3s,
-       E_3 = 1000000/Mi3,
-       F_3 = 1000000/Fa3,
-       Fs_3 = 1000000/Fa3s,
-       G_3 = 1000000/So3,
-       Gs_3 = 1000000/So3s,
-       A_3 = 1000000/La3,
-       As_3 = 1000000/La3s,
-       B_3 = 1000000/Ti3,
-       C_4 = 1000000/Do4,
-       Cs_4 = 1000000/Do4s,
-       D_4 = 1000000/Re4,
-       Ds_4 = 1000000/Re4s,
-       E_4 = 1000000/Mi4,
-       F_4 = 1000000/Fa4,
-       Fs_4 = 1000000/Fa4s,
-       G_4 = 1000000/So4,
-       Gs_4 = 1000000/So4s,
-       A_4 = 1000000/La4,
-       As_4 = 1000000/La4s,
-       B_4 = 1000000/Ti4,
-       C_5 = 1000000/Do5,
-       Cs_5 = 1000000/Do5s,
-       D_5 = 1000000/Re5,
-       Ds_5 = 1000000/Re5s,
-       E_5 = 1000000/Mi5,
-       F_5 = 1000000/Fa5,
-       Fs_5 = 1000000/Fa5s,
-       G_5 = 1000000/So5,
-       Gs_5 = 1000000/So5s,
-       A_5 = 1000000/La5,
-       As_5 = 1000000/La5s,
-       B_5 = 1000000/Ti5;
-       
-int tones[] = {E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, D_4, 0, E_4, G_4, G_4, 0, 
-                             E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, E_4, D_4, C_4, 0, 0, 0};
-int tones_num = 32;
-*/
-                         
+
+
+float airValue;                       
 float multiplier = 50;    // this number got me closest to the reading on my multimeter temp probe
 float temp;               // calculated temperature
 int count;                // for computing average reading
@@ -71,10 +35,12 @@
 float average;
 float max = 22;
 float min = 20;
-int Boiler_max = min + 2;
+// int Boiler_max = min + 2;
 void initialize();
 void buzz()
-{
+
+
+        {
        for (float i=2000.0; i<7000.0; i+=1000) {
             spkr.period(0.5/i);
             spkr=0.1;
@@ -83,6 +49,7 @@
         spkr=0.0;
 }
 
+
 int main() 
 {
     initialize(); 
@@ -93,16 +60,26 @@
     g = 1;
     buzz();
     
+       
+    
+    
+    
     
     
     
     while (1) {
+        
         // formula is analog reading * multiplier
-
+        airValue = air.read()* 100; // returns voltage between 0 -> 1
         temp = sensor.read() * multiplier;
         count++;
         total += temp;
         average = total / count;
+        
+        
+        
+        
+        
         // min = min * 1;
         
            if (Up) 
@@ -161,18 +138,47 @@
          Ctrl2 = 1;
          
         }
+        
+        if (airValue > 80 )
+        {
+        leds =1;
+        }
+        
+        if (airValue < 80 )
+        {
+        leds =0;
+        }
+        
         else
         {
         
         }
         
+        
+    
+       
+                
         lcd.cls();
         lcd.locate(0,0);
         lcd.printf("Temp= %6.2f  Avg= %5.1f ", temp  , average );
-        lcd.locate(0,12);
+        lcd.locate(0,10);
         lcd.printf("min= %6.0f max= %6.0f", min, max);
         
+        lcd.locate(0,20);
+        lcd.printf("Air Quality %f \n\r",airValue);     
+        
         wait(0.5); 
+     
+        pc.printf(" \n\r");
+        pc.printf("Thermostat values\n\r");
+        pc.printf("Temp= %6.2f  Avg= %5.1f \n\r", temp  , average );
+        pc.printf("min= %6.0f max= %6.0f \n \r", min, max);
+        pc.printf("Air Quality %f \n \r",airValue);  
+        pc.printf(" \n\r");
+     
+        
+        
+        
         }
 
 }