current code

Dependencies:   mbed Motor TextLCD Keypad Frdmlz25 DHT11

Dependents:   Frdmlz25

Revision:
0:dc0a6c236ec1
Child:
1:c7d87cc6718a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 01 23:20:14 2018 +0000
@@ -0,0 +1,260 @@
+ #include "mbed.h"
+#include "Dht11.h"
+#include "TSL2561.h"
+#include "Keypad.h"
+#include "TextLCD.h"
+
+//Setup a new plant1 data
+float p1_tMin=35.0, p1_tMax=45.0;
+float p1_lMin=300.0, p1_lMax=50000.0;
+float p1_hMin=60.0, p1_hMax=70.0;
+//Setup a new plant2 data
+float p2_tMin=10.0, p2_tMax=25.0;
+float p2_lMin=200.0, p2_lMax=50000.0;
+float p2_hMin=10.0, p2_hMax=40.0;
+//Setup a new plant3 data
+float p3_tMin=15.0, p3_tMax=25.0;
+float p3_lMin=100.0, p3_lMax=50000.0;
+float p3_hMin=30.0, p3_hMax=70.0;
+
+Serial PC(PTE0, PTE1);
+#define PC_PRINTX(z,x)             if(z==1) PC.printf(x);
+#define PC_PRINTLNX(z,x)           if(z==1) {PC.printf(x);        PC.printf("\r\n");}
+#define PC_PRINTXY(z,x, y)         if(z==1) PC.printf(x, y);
+#define PC_PRINTLNXY(z,x, y)       if(z==1) {PC.printf(x, y);     PC.printf("\r\n");}
+ 
+
+//Setup a new plant data
+
+Dht11 sensor(PTB0);
+TSL2561 tsl2561(TSL2561_ADDR_FLOAT);// Use the tsl2561 sensor
+
+
+//Setup output
+DigitalOut output1(PTD3);  //Setup output
+DigitalOut output2(PTD2);  //Setup output
+DigitalOut output3(PTE5);  //Setup output
+DigitalOut output4(PTD5);  //Setup output
+Keypad KeyInput(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5);
+TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3,TextLCD::LCD16x2);
+//float output1=0,output2=0,output3=0,output4=0;// lighting// ventilation// watering// heating
+
+         
+                                      
+               
+int main() {
+    int val_hud;
+    char keym;
+    uint16_t val_lig;
+    float val_tmp,t;  
+//    int output1,output2,output3,output4;
+    
+    
+    lcd.printf("-----START------");
+    wait(2);
+    lcd.printf("WELCOME TO 6711");
+    wait(3);
+    
+   
+    
+    while (1) {
+            lcd.printf("Please input the No. of plant");
+            wait(0.2);
+            keym=KeyInput.ReadKey(); 
+            lcd.cls();
+            if (keym!='\0') {
+                lcd.printf("The type of plant is %c",keym);
+                wait(3);
+                lcd.cls();;
+                
+                //while(keym!='0') {
+                while(1) {
+                    //keym=KeyInput.ReadKey(); // input a key see if it is the key to trun out 
+                   // if (keym=='\0'){
+                  //      release=1;
+                 //      }
+                //   if ((keym!='\0')&&(release==1)) {
+                   
+                    //  release=0;
+                   //     }
+                                      
+                    // get temperature and humidity data from sensor
+                    sensor.read();
+                    t=sensor.getFahrenheit();
+                    val_tmp=(t-32)/1.8;
+                    val_hud=sensor.getHumidity();
+                    lcd.printf("T: %2.1fC\n", val_tmp);
+                    lcd.printf("H: %d%%\n",val_hud); 
+                    wait(3);
+                    lcd.cls();
+                    
+                    // get light data
+                    val_lig = tsl2561.getLuminosity(TSL2561_VISIBLE);     
+                    //option2 x = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM);
+                    //option3 x = tsl2561.getLuminosity(TSL2561_INFRARED);
+                    lcd.printf("Illu is:%d Lux\n",val_lig); 
+                    wait(2);
+                    lcd.cls();
+                    //keym=KeyInput.ReadKey();
+                    // compare data
+                    lcd.printf("key is:%c \n",keym); 
+                    wait(2);
+                    if (keym=='1') {
+                        lcd.printf("successfel:\n"); 
+                        wait(2);
+                        if (val_tmp>=p1_tMin && val_tmp<=p1_tMax)   {
+                            if (val_hud>=p1_hMin && val_hud<=p1_hMax) {
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=0;
+                                    output3=0;
+                                    output4=0;
+                                    }
+                                else if (val_lig<p1_lMin){
+                                    output1=1; 
+                                    output2=0;
+                                    output3=0;
+                                    output4=0;
+                                    }
+                                }
+                            
+                                
+                            else if (val_hud<=p1_hMin ) {
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=0;
+                                    output3=1;
+                                    output4=0;
+                                    }
+                                else if (val_lig<p1_lMin){
+                                    output1=1; 
+                                    output2=0;
+                                    output3=1;
+                                    output4=0;
+                                    }
+                                }
+                            else    {
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=1;
+                                    output3=0;
+                                    output4=0;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=1;
+                                    output3=0;
+                                    output4=0;
+                                    }
+                                }
+                                
+                            
+                            }
+                        else if (val_tmp<=p1_tMin){
+                            if (val_hud>=p1_hMin && val_hud<=p1_hMax){
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=0;
+                                    output3=0;
+                                    output4=1;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=0;
+                                    output3=0;
+                                    output4=1;
+                                    }
+                                }
+                                
+                            else if (val_hud<=p1_hMin ) {
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=0;
+                                    output3=1;
+                                    output4=1;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=0;
+                                    output3=1;
+                                    output4=1;
+                                    }
+                                }
+                            else    {
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=1;
+                                    output3=0;
+                                    output4=1;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=1;
+                                    output3=0;
+                                    output4=1;
+                                    }
+                                }
+                            }
+                            
+                       
+                                
+                        else{
+                            if (val_hud>=p1_hMin && val_hud<=p1_hMax){
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=1;
+                                    output3=1;
+                                    output4=0;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=1;
+                                    output3=1;
+                                    output4=0;
+                                    }
+                                }
+                                
+                            else if (val_hud<=p1_hMin ) {
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=1;
+                                    output3=1;
+                                    output4=0;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=1;
+                                    output3=1;
+                                    output4=0;
+                                    }
+                                }
+                            else{
+                                if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
+                                    output1=0;
+                                    output2=1;
+                                    output3=0;
+                                    output4=0;
+                                    }
+                                else if (val_lig<=p1_lMin){
+                                    output1=1; 
+                                    output2=1;
+                                    output3=0;
+                                    output4=0;
+                                    }
+                                }
+                            }
+            
+    
+      
+                    //else if (keym=='2') {
+                   //     Output(keym,val_tmp,val_hud,val_lig,p2_tMin,p2_tMax,p2_hMin,p2_hMax,p2_lMin,p2_lMax);
+                       // lcd.printf("%d",output1);
+                    //    }
+                  //  else
+                   //     Output(keym,val_tmp,val_hud,val_lig,p3_tMin,p3_tMax,p3_hMin,p3_hMax,p3_lMin,p3_lMax);
+                
+             }
+         }
+        }
+    }
+}