current code
Dependencies: mbed Motor TextLCD Keypad Frdmlz25 DHT11
main.cpp@0:dc0a6c236ec1, 2018-11-01 (annotated)
- Committer:
- alex123456
- Date:
- Thu Nov 01 23:20:14 2018 +0000
- Revision:
- 0:dc0a6c236ec1
- Child:
- 1:c7d87cc6718a
tttttt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex123456 | 0:dc0a6c236ec1 | 1 | #include "mbed.h" |
alex123456 | 0:dc0a6c236ec1 | 2 | #include "Dht11.h" |
alex123456 | 0:dc0a6c236ec1 | 3 | #include "TSL2561.h" |
alex123456 | 0:dc0a6c236ec1 | 4 | #include "Keypad.h" |
alex123456 | 0:dc0a6c236ec1 | 5 | #include "TextLCD.h" |
alex123456 | 0:dc0a6c236ec1 | 6 | |
alex123456 | 0:dc0a6c236ec1 | 7 | //Setup a new plant1 data |
alex123456 | 0:dc0a6c236ec1 | 8 | float p1_tMin=35.0, p1_tMax=45.0; |
alex123456 | 0:dc0a6c236ec1 | 9 | float p1_lMin=300.0, p1_lMax=50000.0; |
alex123456 | 0:dc0a6c236ec1 | 10 | float p1_hMin=60.0, p1_hMax=70.0; |
alex123456 | 0:dc0a6c236ec1 | 11 | //Setup a new plant2 data |
alex123456 | 0:dc0a6c236ec1 | 12 | float p2_tMin=10.0, p2_tMax=25.0; |
alex123456 | 0:dc0a6c236ec1 | 13 | float p2_lMin=200.0, p2_lMax=50000.0; |
alex123456 | 0:dc0a6c236ec1 | 14 | float p2_hMin=10.0, p2_hMax=40.0; |
alex123456 | 0:dc0a6c236ec1 | 15 | //Setup a new plant3 data |
alex123456 | 0:dc0a6c236ec1 | 16 | float p3_tMin=15.0, p3_tMax=25.0; |
alex123456 | 0:dc0a6c236ec1 | 17 | float p3_lMin=100.0, p3_lMax=50000.0; |
alex123456 | 0:dc0a6c236ec1 | 18 | float p3_hMin=30.0, p3_hMax=70.0; |
alex123456 | 0:dc0a6c236ec1 | 19 | |
alex123456 | 0:dc0a6c236ec1 | 20 | Serial PC(PTE0, PTE1); |
alex123456 | 0:dc0a6c236ec1 | 21 | #define PC_PRINTX(z,x) if(z==1) PC.printf(x); |
alex123456 | 0:dc0a6c236ec1 | 22 | #define PC_PRINTLNX(z,x) if(z==1) {PC.printf(x); PC.printf("\r\n");} |
alex123456 | 0:dc0a6c236ec1 | 23 | #define PC_PRINTXY(z,x, y) if(z==1) PC.printf(x, y); |
alex123456 | 0:dc0a6c236ec1 | 24 | #define PC_PRINTLNXY(z,x, y) if(z==1) {PC.printf(x, y); PC.printf("\r\n");} |
alex123456 | 0:dc0a6c236ec1 | 25 | |
alex123456 | 0:dc0a6c236ec1 | 26 | |
alex123456 | 0:dc0a6c236ec1 | 27 | //Setup a new plant data |
alex123456 | 0:dc0a6c236ec1 | 28 | |
alex123456 | 0:dc0a6c236ec1 | 29 | Dht11 sensor(PTB0); |
alex123456 | 0:dc0a6c236ec1 | 30 | TSL2561 tsl2561(TSL2561_ADDR_FLOAT);// Use the tsl2561 sensor |
alex123456 | 0:dc0a6c236ec1 | 31 | |
alex123456 | 0:dc0a6c236ec1 | 32 | |
alex123456 | 0:dc0a6c236ec1 | 33 | //Setup output |
alex123456 | 0:dc0a6c236ec1 | 34 | DigitalOut output1(PTD3); //Setup output |
alex123456 | 0:dc0a6c236ec1 | 35 | DigitalOut output2(PTD2); //Setup output |
alex123456 | 0:dc0a6c236ec1 | 36 | DigitalOut output3(PTE5); //Setup output |
alex123456 | 0:dc0a6c236ec1 | 37 | DigitalOut output4(PTD5); //Setup output |
alex123456 | 0:dc0a6c236ec1 | 38 | Keypad KeyInput(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5); |
alex123456 | 0:dc0a6c236ec1 | 39 | TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3,TextLCD::LCD16x2); |
alex123456 | 0:dc0a6c236ec1 | 40 | //float output1=0,output2=0,output3=0,output4=0;// lighting// ventilation// watering// heating |
alex123456 | 0:dc0a6c236ec1 | 41 | |
alex123456 | 0:dc0a6c236ec1 | 42 | |
alex123456 | 0:dc0a6c236ec1 | 43 | |
alex123456 | 0:dc0a6c236ec1 | 44 | |
alex123456 | 0:dc0a6c236ec1 | 45 | int main() { |
alex123456 | 0:dc0a6c236ec1 | 46 | int val_hud; |
alex123456 | 0:dc0a6c236ec1 | 47 | char keym; |
alex123456 | 0:dc0a6c236ec1 | 48 | uint16_t val_lig; |
alex123456 | 0:dc0a6c236ec1 | 49 | float val_tmp,t; |
alex123456 | 0:dc0a6c236ec1 | 50 | // int output1,output2,output3,output4; |
alex123456 | 0:dc0a6c236ec1 | 51 | |
alex123456 | 0:dc0a6c236ec1 | 52 | |
alex123456 | 0:dc0a6c236ec1 | 53 | lcd.printf("-----START------"); |
alex123456 | 0:dc0a6c236ec1 | 54 | wait(2); |
alex123456 | 0:dc0a6c236ec1 | 55 | lcd.printf("WELCOME TO 6711"); |
alex123456 | 0:dc0a6c236ec1 | 56 | wait(3); |
alex123456 | 0:dc0a6c236ec1 | 57 | |
alex123456 | 0:dc0a6c236ec1 | 58 | |
alex123456 | 0:dc0a6c236ec1 | 59 | |
alex123456 | 0:dc0a6c236ec1 | 60 | while (1) { |
alex123456 | 0:dc0a6c236ec1 | 61 | lcd.printf("Please input the No. of plant"); |
alex123456 | 0:dc0a6c236ec1 | 62 | wait(0.2); |
alex123456 | 0:dc0a6c236ec1 | 63 | keym=KeyInput.ReadKey(); |
alex123456 | 0:dc0a6c236ec1 | 64 | lcd.cls(); |
alex123456 | 0:dc0a6c236ec1 | 65 | if (keym!='\0') { |
alex123456 | 0:dc0a6c236ec1 | 66 | lcd.printf("The type of plant is %c",keym); |
alex123456 | 0:dc0a6c236ec1 | 67 | wait(3); |
alex123456 | 0:dc0a6c236ec1 | 68 | lcd.cls();; |
alex123456 | 0:dc0a6c236ec1 | 69 | |
alex123456 | 0:dc0a6c236ec1 | 70 | //while(keym!='0') { |
alex123456 | 0:dc0a6c236ec1 | 71 | while(1) { |
alex123456 | 0:dc0a6c236ec1 | 72 | //keym=KeyInput.ReadKey(); // input a key see if it is the key to trun out |
alex123456 | 0:dc0a6c236ec1 | 73 | // if (keym=='\0'){ |
alex123456 | 0:dc0a6c236ec1 | 74 | // release=1; |
alex123456 | 0:dc0a6c236ec1 | 75 | // } |
alex123456 | 0:dc0a6c236ec1 | 76 | // if ((keym!='\0')&&(release==1)) { |
alex123456 | 0:dc0a6c236ec1 | 77 | |
alex123456 | 0:dc0a6c236ec1 | 78 | // release=0; |
alex123456 | 0:dc0a6c236ec1 | 79 | // } |
alex123456 | 0:dc0a6c236ec1 | 80 | |
alex123456 | 0:dc0a6c236ec1 | 81 | // get temperature and humidity data from sensor |
alex123456 | 0:dc0a6c236ec1 | 82 | sensor.read(); |
alex123456 | 0:dc0a6c236ec1 | 83 | t=sensor.getFahrenheit(); |
alex123456 | 0:dc0a6c236ec1 | 84 | val_tmp=(t-32)/1.8; |
alex123456 | 0:dc0a6c236ec1 | 85 | val_hud=sensor.getHumidity(); |
alex123456 | 0:dc0a6c236ec1 | 86 | lcd.printf("T: %2.1fC\n", val_tmp); |
alex123456 | 0:dc0a6c236ec1 | 87 | lcd.printf("H: %d%%\n",val_hud); |
alex123456 | 0:dc0a6c236ec1 | 88 | wait(3); |
alex123456 | 0:dc0a6c236ec1 | 89 | lcd.cls(); |
alex123456 | 0:dc0a6c236ec1 | 90 | |
alex123456 | 0:dc0a6c236ec1 | 91 | // get light data |
alex123456 | 0:dc0a6c236ec1 | 92 | val_lig = tsl2561.getLuminosity(TSL2561_VISIBLE); |
alex123456 | 0:dc0a6c236ec1 | 93 | //option2 x = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM); |
alex123456 | 0:dc0a6c236ec1 | 94 | //option3 x = tsl2561.getLuminosity(TSL2561_INFRARED); |
alex123456 | 0:dc0a6c236ec1 | 95 | lcd.printf("Illu is:%d Lux\n",val_lig); |
alex123456 | 0:dc0a6c236ec1 | 96 | wait(2); |
alex123456 | 0:dc0a6c236ec1 | 97 | lcd.cls(); |
alex123456 | 0:dc0a6c236ec1 | 98 | //keym=KeyInput.ReadKey(); |
alex123456 | 0:dc0a6c236ec1 | 99 | // compare data |
alex123456 | 0:dc0a6c236ec1 | 100 | lcd.printf("key is:%c \n",keym); |
alex123456 | 0:dc0a6c236ec1 | 101 | wait(2); |
alex123456 | 0:dc0a6c236ec1 | 102 | if (keym=='1') { |
alex123456 | 0:dc0a6c236ec1 | 103 | lcd.printf("successfel:\n"); |
alex123456 | 0:dc0a6c236ec1 | 104 | wait(2); |
alex123456 | 0:dc0a6c236ec1 | 105 | if (val_tmp>=p1_tMin && val_tmp<=p1_tMax) { |
alex123456 | 0:dc0a6c236ec1 | 106 | if (val_hud>=p1_hMin && val_hud<=p1_hMax) { |
alex123456 | 0:dc0a6c236ec1 | 107 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 108 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 109 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 110 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 111 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 112 | } |
alex123456 | 0:dc0a6c236ec1 | 113 | else if (val_lig<p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 114 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 115 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 116 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 117 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 118 | } |
alex123456 | 0:dc0a6c236ec1 | 119 | } |
alex123456 | 0:dc0a6c236ec1 | 120 | |
alex123456 | 0:dc0a6c236ec1 | 121 | |
alex123456 | 0:dc0a6c236ec1 | 122 | else if (val_hud<=p1_hMin ) { |
alex123456 | 0:dc0a6c236ec1 | 123 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 124 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 125 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 126 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 127 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 128 | } |
alex123456 | 0:dc0a6c236ec1 | 129 | else if (val_lig<p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 130 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 131 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 132 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 133 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 134 | } |
alex123456 | 0:dc0a6c236ec1 | 135 | } |
alex123456 | 0:dc0a6c236ec1 | 136 | else { |
alex123456 | 0:dc0a6c236ec1 | 137 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 138 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 139 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 140 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 141 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 142 | } |
alex123456 | 0:dc0a6c236ec1 | 143 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 144 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 145 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 146 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 147 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 148 | } |
alex123456 | 0:dc0a6c236ec1 | 149 | } |
alex123456 | 0:dc0a6c236ec1 | 150 | |
alex123456 | 0:dc0a6c236ec1 | 151 | |
alex123456 | 0:dc0a6c236ec1 | 152 | } |
alex123456 | 0:dc0a6c236ec1 | 153 | else if (val_tmp<=p1_tMin){ |
alex123456 | 0:dc0a6c236ec1 | 154 | if (val_hud>=p1_hMin && val_hud<=p1_hMax){ |
alex123456 | 0:dc0a6c236ec1 | 155 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 156 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 157 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 158 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 159 | output4=1; |
alex123456 | 0:dc0a6c236ec1 | 160 | } |
alex123456 | 0:dc0a6c236ec1 | 161 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 162 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 163 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 164 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 165 | output4=1; |
alex123456 | 0:dc0a6c236ec1 | 166 | } |
alex123456 | 0:dc0a6c236ec1 | 167 | } |
alex123456 | 0:dc0a6c236ec1 | 168 | |
alex123456 | 0:dc0a6c236ec1 | 169 | else if (val_hud<=p1_hMin ) { |
alex123456 | 0:dc0a6c236ec1 | 170 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 171 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 172 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 173 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 174 | output4=1; |
alex123456 | 0:dc0a6c236ec1 | 175 | } |
alex123456 | 0:dc0a6c236ec1 | 176 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 177 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 178 | output2=0; |
alex123456 | 0:dc0a6c236ec1 | 179 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 180 | output4=1; |
alex123456 | 0:dc0a6c236ec1 | 181 | } |
alex123456 | 0:dc0a6c236ec1 | 182 | } |
alex123456 | 0:dc0a6c236ec1 | 183 | else { |
alex123456 | 0:dc0a6c236ec1 | 184 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 185 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 186 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 187 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 188 | output4=1; |
alex123456 | 0:dc0a6c236ec1 | 189 | } |
alex123456 | 0:dc0a6c236ec1 | 190 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 191 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 192 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 193 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 194 | output4=1; |
alex123456 | 0:dc0a6c236ec1 | 195 | } |
alex123456 | 0:dc0a6c236ec1 | 196 | } |
alex123456 | 0:dc0a6c236ec1 | 197 | } |
alex123456 | 0:dc0a6c236ec1 | 198 | |
alex123456 | 0:dc0a6c236ec1 | 199 | |
alex123456 | 0:dc0a6c236ec1 | 200 | |
alex123456 | 0:dc0a6c236ec1 | 201 | else{ |
alex123456 | 0:dc0a6c236ec1 | 202 | if (val_hud>=p1_hMin && val_hud<=p1_hMax){ |
alex123456 | 0:dc0a6c236ec1 | 203 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 204 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 205 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 206 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 207 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 208 | } |
alex123456 | 0:dc0a6c236ec1 | 209 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 210 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 211 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 212 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 213 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 214 | } |
alex123456 | 0:dc0a6c236ec1 | 215 | } |
alex123456 | 0:dc0a6c236ec1 | 216 | |
alex123456 | 0:dc0a6c236ec1 | 217 | else if (val_hud<=p1_hMin ) { |
alex123456 | 0:dc0a6c236ec1 | 218 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 219 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 220 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 221 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 222 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 223 | } |
alex123456 | 0:dc0a6c236ec1 | 224 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 225 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 226 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 227 | output3=1; |
alex123456 | 0:dc0a6c236ec1 | 228 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 229 | } |
alex123456 | 0:dc0a6c236ec1 | 230 | } |
alex123456 | 0:dc0a6c236ec1 | 231 | else{ |
alex123456 | 0:dc0a6c236ec1 | 232 | if (val_lig>=p1_lMin && val_lig<=p1_lMax) { |
alex123456 | 0:dc0a6c236ec1 | 233 | output1=0; |
alex123456 | 0:dc0a6c236ec1 | 234 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 235 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 236 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 237 | } |
alex123456 | 0:dc0a6c236ec1 | 238 | else if (val_lig<=p1_lMin){ |
alex123456 | 0:dc0a6c236ec1 | 239 | output1=1; |
alex123456 | 0:dc0a6c236ec1 | 240 | output2=1; |
alex123456 | 0:dc0a6c236ec1 | 241 | output3=0; |
alex123456 | 0:dc0a6c236ec1 | 242 | output4=0; |
alex123456 | 0:dc0a6c236ec1 | 243 | } |
alex123456 | 0:dc0a6c236ec1 | 244 | } |
alex123456 | 0:dc0a6c236ec1 | 245 | } |
alex123456 | 0:dc0a6c236ec1 | 246 | |
alex123456 | 0:dc0a6c236ec1 | 247 | |
alex123456 | 0:dc0a6c236ec1 | 248 | |
alex123456 | 0:dc0a6c236ec1 | 249 | //else if (keym=='2') { |
alex123456 | 0:dc0a6c236ec1 | 250 | // Output(keym,val_tmp,val_hud,val_lig,p2_tMin,p2_tMax,p2_hMin,p2_hMax,p2_lMin,p2_lMax); |
alex123456 | 0:dc0a6c236ec1 | 251 | // lcd.printf("%d",output1); |
alex123456 | 0:dc0a6c236ec1 | 252 | // } |
alex123456 | 0:dc0a6c236ec1 | 253 | // else |
alex123456 | 0:dc0a6c236ec1 | 254 | // Output(keym,val_tmp,val_hud,val_lig,p3_tMin,p3_tMax,p3_hMin,p3_hMax,p3_lMin,p3_lMax); |
alex123456 | 0:dc0a6c236ec1 | 255 | |
alex123456 | 0:dc0a6c236ec1 | 256 | } |
alex123456 | 0:dc0a6c236ec1 | 257 | } |
alex123456 | 0:dc0a6c236ec1 | 258 | } |
alex123456 | 0:dc0a6c236ec1 | 259 | } |
alex123456 | 0:dc0a6c236ec1 | 260 | } |