current code
Dependencies: mbed Motor TextLCD Keypad Frdmlz25 DHT11
Diff: main.cpp
- Revision:
- 1:c7d87cc6718a
- Parent:
- 0:dc0a6c236ec1
- Child:
- 2:8ed2269ab264
- Child:
- 5:83908d1e6213
--- a/main.cpp Thu Nov 01 23:20:14 2018 +0000 +++ b/main.cpp Fri Nov 02 00:13:56 2018 +0000 @@ -44,7 +44,7 @@ int main() { int val_hud; - char keym; + char keym,tempkey; uint16_t val_lig; float val_tmp,t; // int output1,output2,output3,output4; @@ -61,6 +61,7 @@ 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); @@ -69,14 +70,18 @@ //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)) { + 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; + } - // release=0; - // } + } // get temperature and humidity data from sensor sensor.read(); @@ -90,18 +95,14 @@ // 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) { @@ -244,16 +245,297 @@ } } - - - //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); + } + //-------------------------- 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; + } + } + } + } - } + } } }