current code

Dependencies:   mbed Motor TextLCD Keypad Frdmlz25 DHT11

Dependents:   Frdmlz25

main.cpp

Committer:
alex123456
Date:
2018-11-02
Revision:
1:c7d87cc6718a
Parent:
0:dc0a6c236ec1
Child:
2:8ed2269ab264
Child:
5:83908d1e6213

File content as of revision 1:c7d87cc6718a:

 #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,tempkey;
    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(); 
            tempkey=keym;
            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'){
                        keym=tempkey;
                       }
                    else if (keym!='\0') {
                        lcd.printf("If you want reset, plesee input zer0 !");
                        keym=KeyInput.ReadKey();
                        if (keym=='0'){
                            break;
                            }
                   
                        }
                                      
                    // 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);     
                    lcd.printf("Illu is:%d Lux\n",val_lig); 
                    wait(2);
                    lcd.cls();
                    
                    // compare data
                    lcd.printf("key is:%c \n",keym); 
                    wait(2);
                    if (keym=='1') {
                        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;
                                    }
                                }
                            }
            
                    }
   //-------------------------- sceond type-----------------------------------------   
                    else if (keym=='2') {
                        if (val_tmp>=p2_tMin && val_tmp<=p2_tMax)   {
                            if (val_hud>=p2_hMin && val_hud<=p2_hMax) {
                                if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=0;
                                    output3=0;
                                    output4=0;
                                    }
                                else if (val_lig<p2_lMin){
                                    output1=1; 
                                    output2=0;
                                    output3=0;
                                    output4=0;
                                    }
                                }
                            
                                
                            else if (val_hud<=p2_hMin ) {
                                if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=0;
                                    output3=1;
                                    output4=0;
                                    }
                                else if (val_lig<p2_lMin){
                                    output1=1; 
                                    output2=0;
                                    output3=1;
                                    output4=0;
                                    }
                                }
                            else    {
                                if (val_lig>=p2_lMin && val_lig<=p2_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>=p2_hMin && val_hud<=p2_hMax){
                                if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=0;
                                    output3=0;
                                    output4=1;
                                    }
                                else if (val_lig<=p2_lMin){
                                    output1=1; 
                                    output2=0;
                                    output3=0;
                                    output4=1;
                                    }
                                }
                                
                            else if (val_hud<=p2_hMin ) {
                                if (val_lig>=p2_lMin && val_lig<=p2_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>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=1;
                                    output3=0;
                                    output4=1;
                                    }
                                else if (val_lig<=p2_lMin){
                                    output1=1; 
                                    output2=1;
                                    output3=0;
                                    output4=1;
                                    }
                                }
                            }
                            
                       
                                
                        else{
                            if (val_hud>=p2_hMin && val_hud<=p2_hMax){
                                if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=1;
                                    output3=1;
                                    output4=0;
                                    }
                                else if (val_lig<=p2_lMin){
                                    output1=1; 
                                    output2=1;
                                    output3=1;
                                    output4=0;
                                    }
                                }
                                
                            else if (val_hud<=p2_hMin ) {
                                if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=1;
                                    output3=1;
                                    output4=0;
                                    }
                                else if (val_lig<=p2_lMin){
                                    output1=1; 
                                    output2=1;
                                    output3=1;
                                    output4=0;
                                    }
                                }
                            else{
                                if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                    output1=0;
                                    output2=1;
                                    output3=0;
                                    output4=0;
                                    }
                                else if (val_lig<=p2_lMin){
                                    output1=1; 
                                    output2=1;
                                    output3=0;
                                    output4=0;
                                    }
                                }
                            }
                        }
   //-------------------------- Third type-----------------------------------------   
                    else{
                        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;
                                    }
                                }
                            }
                        }
                
             
         }
        }
    }
}