Project Autus - Automated Plant Chamber
Fork of keypad_test by
Autus
This is the codebase accompanying the project Autus.
Autus is an automated growth chamber for plants.
Features
Control Humidity inside chamber wrt to external humidity.
Control Temperature inside chamber. ( Peltier Heaters/Coolers )
Water and shower plants.
Control soil humidity.
Monitor water tanks level (Load Cell)
Code Base Features
Fixed timing and CRC for DHT-11 Sensor. Fixed OneWire bug for ds18b20
Cyclic Executive Scheduler with Priority. Async IPC framework for PC App over bluetooth
Fake RTC systick, I was having some trouble with the on board rtc.
main.cpp@57:7ab93ed49b70, 2014-04-14 (annotated)
- Committer:
- umairaftab
- Date:
- Mon Apr 14 19:18:14 2014 +0000
- Revision:
- 57:7ab93ed49b70
- Parent:
- 56:d1e81ca74f22
Cosmetic Changes, Menus added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
umairaftab | 8:2d462919519e | 1 | |
umairaftab | 8:2d462919519e | 2 | //QUICK REFS: |
umairaftab | 8:2d462919519e | 3 | // TICKER is using timer 1 for buzzer. |
umairaftab | 8:2d462919519e | 4 | |
umairaftab | 1:9ef26efedcea | 5 | #include "mbed.h" |
umairaftab | 3:087ce66714c0 | 6 | |
umairaftab | 1:9ef26efedcea | 7 | #include "keypad.h" |
umairaftab | 1:9ef26efedcea | 8 | #include "buzz.h" |
umairaftab | 7:1d691f81d455 | 9 | |
umairaftab | 7:1d691f81d455 | 10 | #include "pindefs.h" //led pin definitions |
umairaftab | 3:087ce66714c0 | 11 | #include "led_lights.h" |
umairaftab | 7:1d691f81d455 | 12 | |
umairaftab | 3:087ce66714c0 | 13 | #include "peltier.h" |
umairaftab | 7:1d691f81d455 | 14 | #include "peltier_pindefs.h" |
umairaftab | 7:1d691f81d455 | 15 | |
umairaftab | 7:1d691f81d455 | 16 | #include "pumps.h" |
umairaftab | 7:1d691f81d455 | 17 | #include "pumps_pindefs.h" |
umairaftab | 7:1d691f81d455 | 18 | |
umairaftab | 7:1d691f81d455 | 19 | #include "airhumidity.h" |
umairaftab | 7:1d691f81d455 | 20 | #include "soilmoisture.h" |
umairaftab | 7:1d691f81d455 | 21 | #include "soilmoisture_pindefs.h" |
umairaftab | 8:2d462919519e | 22 | |
umairaftab | 7:1d691f81d455 | 23 | #include "ui.h" |
umairaftab | 7:1d691f81d455 | 24 | #include "ui_pindefs.h" |
umairaftab | 7:1d691f81d455 | 25 | #include "TextLCD.h" |
umairaftab | 7:1d691f81d455 | 26 | |
umairaftab | 8:2d462919519e | 27 | #include "rtcimp.h" |
umairaftab | 8:2d462919519e | 28 | |
umairaftab | 14:72176f1e4907 | 29 | #include "weight.h" |
umairaftab | 14:72176f1e4907 | 30 | #include "weight_pindefs.h" |
umairaftab | 14:72176f1e4907 | 31 | |
umairaftab | 36:ce0ca02a8253 | 32 | #include "cycleair.h" |
umairaftab | 36:ce0ca02a8253 | 33 | #include "cycleair_pindef.h" |
umairaftab | 36:ce0ca02a8253 | 34 | |
umairaftab | 42:41f6c241a987 | 35 | #include "DS18B20.h" |
umairaftab | 42:41f6c241a987 | 36 | #include "OneWireDefs.h" |
umairaftab | 42:41f6c241a987 | 37 | |
umairaftab | 12:b3137bb72ef7 | 38 | #include <string> |
umairaftab | 12:b3137bb72ef7 | 39 | using namespace std; |
umairaftab | 12:b3137bb72ef7 | 40 | |
umairaftab | 54:1302a97c84aa | 41 | #define BAUDRATE0 1200 |
umairaftab | 54:1302a97c84aa | 42 | #define BAUDRATE1 2400 |
umairaftab | 54:1302a97c84aa | 43 | #define BAUDRATE3 2400 |
umairaftab | 54:1302a97c84aa | 44 | |
umairaftab | 8:2d462919519e | 45 | //SERIAL |
umairaftab | 36:ce0ca02a8253 | 46 | Serial bluetooth_dev(PTA2, PTA1); // tx, rx |
umairaftab | 8:2d462919519e | 47 | Serial printer(PTC4,PTC3); // tx, rx |
umairaftab | 8:2d462919519e | 48 | //TICKERS |
umairaftab | 1:9ef26efedcea | 49 | Ticker timer1ms; |
umairaftab | 8:2d462919519e | 50 | Ticker clock_mine; |
umairaftab | 11:f9ffd5ab7e94 | 51 | Timer lcd_timeout; |
umairaftab | 8:2d462919519e | 52 | //FLAGS |
umairaftab | 8:2d462919519e | 53 | bool startup_flag=true; |
umairaftab | 9:43c339533f7f | 54 | bool watered_plant1 = false; |
umairaftab | 9:43c339533f7f | 55 | int watered_plant1_time = 0; |
umairaftab | 9:43c339533f7f | 56 | bool watered_plant2 = false; |
umairaftab | 9:43c339533f7f | 57 | int watered_plant2_time = 0; |
umairaftab | 8:2d462919519e | 58 | |
umairaftab | 8:2d462919519e | 59 | //SETPOINTS |
umairaftab | 8:2d462919519e | 60 | float setpoint_air_humidity = 30.00 ; |
umairaftab | 8:2d462919519e | 61 | float setpoint_soil_humid1 = 0.3 ; |
umairaftab | 8:2d462919519e | 62 | float setpoint_soil_humid2 = 0.3 ; |
umairaftab | 8:2d462919519e | 63 | |
umairaftab | 12:b3137bb72ef7 | 64 | float setpoint_MAX_air_temp = 45; |
umairaftab | 12:b3137bb72ef7 | 65 | |
umairaftab | 11:f9ffd5ab7e94 | 66 | int setpoint_red_lights; |
umairaftab | 11:f9ffd5ab7e94 | 67 | int setpoint_blue_lights; |
umairaftab | 11:f9ffd5ab7e94 | 68 | int setpoint_green_lights; |
umairaftab | 12:b3137bb72ef7 | 69 | |
umairaftab | 8:2d462919519e | 70 | //WINDOWING |
umairaftab | 9:43c339533f7f | 71 | float window_f = 5 ; |
umairaftab | 8:2d462919519e | 72 | int window_i =2 ; |
umairaftab | 8:2d462919519e | 73 | |
umairaftab | 8:2d462919519e | 74 | //GLOBAL VARS |
umairaftab | 8:2d462919519e | 75 | float current_water_level = 0; |
umairaftab | 12:b3137bb72ef7 | 76 | bool lcd_timeout_flag=false; |
umairaftab | 38:9f4107db1bff | 77 | |
umairaftab | 37:892872c3fa96 | 78 | int led_set_time=0; |
umairaftab | 37:892872c3fa96 | 79 | int led_off_time=0; |
umairaftab | 37:892872c3fa96 | 80 | bool lights_startup_flag=true; |
umairaftab | 38:9f4107db1bff | 81 | |
umairaftab | 37:892872c3fa96 | 82 | int sensor_function_call_time=0; |
umairaftab | 38:9f4107db1bff | 83 | |
umairaftab | 38:9f4107db1bff | 84 | int pelt_call_time=0; |
umairaftab | 38:9f4107db1bff | 85 | |
umairaftab | 38:9f4107db1bff | 86 | float desire_temp=40; |
umairaftab | 50:7e3e6e3ed8ef | 87 | float desire_temp_air=30; |
umairaftab | 38:9f4107db1bff | 88 | bool pelt_keypad_enable=false; |
umairaftab | 38:9f4107db1bff | 89 | bool pelt_first_time = true; |
umairaftab | 38:9f4107db1bff | 90 | bool pelt_overheat = false; |
umairaftab | 8:2d462919519e | 91 | //SAFETY LIMITS |
umairaftab | 38:9f4107db1bff | 92 | const float max_peltier_temp = 50 ; //CELCIUS |
umairaftab | 12:b3137bb72ef7 | 93 | const int MAX_WATERING_TIME_GAP = 20; //Number of Hours |
umairaftab | 12:b3137bb72ef7 | 94 | const int CYCLE_AIR_TIME = 2; //Wait between on and off seconds |
umairaftab | 12:b3137bb72ef7 | 95 | const int LCD_TIMEOUT_VALUE = 30; //Number of seconds |
umairaftab | 36:ce0ca02a8253 | 96 | const char status = 'F'; //For bluetooth Serial |
umairaftab | 38:9f4107db1bff | 97 | const int led_lights_timeout=5; // Timeout afterwhich to turn off/on lights hours |
umairaftab | 37:892872c3fa96 | 98 | const int sensor_function_call_timeout=3; //Timeout for sensorcall and function |
umairaftab | 38:9f4107db1bff | 99 | const int pelt_call_timeout=30; |
umairaftab | 36:ce0ca02a8253 | 100 | |
umairaftab | 36:ce0ca02a8253 | 101 | //*************************FUNCTION CALLBACK FOR SERIAL INTTERUPTS******************************** |
umairaftab | 36:ce0ca02a8253 | 102 | void callback_bluetooth() { |
umairaftab | 36:ce0ca02a8253 | 103 | // Note: you need to actually read from the serial to clear the RX interrupt |
umairaftab | 36:ce0ca02a8253 | 104 | if(bluetooth_dev.getc()=='S'){ |
umairaftab | 36:ce0ca02a8253 | 105 | |
umairaftab | 36:ce0ca02a8253 | 106 | printf("Info %c %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f \n\r", status,outside_temp,inside_temp,inside_humidity,outside_humidity,inside_dewpoint,outside_dewpoint,soil1_humid,soil2_humid) ; |
umairaftab | 36:ce0ca02a8253 | 107 | |
umairaftab | 36:ce0ca02a8253 | 108 | //myled = !myled; |
umairaftab | 36:ce0ca02a8253 | 109 | } |
umairaftab | 36:ce0ca02a8253 | 110 | //printf("%c\n\r", device.getc()); |
umairaftab | 36:ce0ca02a8253 | 111 | |
umairaftab | 36:ce0ca02a8253 | 112 | } |
umairaftab | 12:b3137bb72ef7 | 113 | |
umairaftab | 54:1302a97c84aa | 114 | void printer_print_values(){ |
umairaftab | 54:1302a97c84aa | 115 | |
umairaftab | 57:7ab93ed49b70 | 116 | //printf("\r****Autus Sensor Values****\r"); |
umairaftab | 54:1302a97c84aa | 117 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 118 | printer.printf("Chamber Temp: %4.2f\r",inside_temp); |
umairaftab | 54:1302a97c84aa | 119 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 120 | printer.printf("Chamber Humidity: %4.2f\r",inside_humidity); |
umairaftab | 55:0bfa6b62a66b | 121 | //wait(1); |
umairaftab | 55:0bfa6b62a66b | 122 | //printer.printf("Chamber Dewpoint: %4.2f\r",inside_dewpoint); |
umairaftab | 54:1302a97c84aa | 123 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 124 | printer.printf("External Temp: %4.2f\r",outside_temp); |
umairaftab | 54:1302a97c84aa | 125 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 126 | printer.printf("External Humidity: %4.2f\r",outside_humidity); |
umairaftab | 55:0bfa6b62a66b | 127 | //wait(1); |
umairaftab | 55:0bfa6b62a66b | 128 | //printer.printf("External Dewpoint: %4.2f\r",outside_dewpoint); |
umairaftab | 54:1302a97c84aa | 129 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 130 | printer.printf("Soil Moisture-1: %4.2f\r",soil1_humid); |
umairaftab | 54:1302a97c84aa | 131 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 132 | printer.printf("Soil Moisture-2: %4.2f\r",soil2_humid); |
umairaftab | 54:1302a97c84aa | 133 | wait(1); |
umairaftab | 55:0bfa6b62a66b | 134 | printer.printf("Load Cell: %4.2f\r",weight_sensor); |
umairaftab | 54:1302a97c84aa | 135 | wait(1); |
umairaftab | 56:d1e81ca74f22 | 136 | printer.printf("**********END**********\r"); |
umairaftab | 54:1302a97c84aa | 137 | } |
umairaftab | 12:b3137bb72ef7 | 138 | |
umairaftab | 8:2d462919519e | 139 | //**************************FUNCTION TO READ SENSORS ********************************************** |
umairaftab | 8:2d462919519e | 140 | void read_sensors(){ |
umairaftab | 8:2d462919519e | 141 | |
umairaftab | 8:2d462919519e | 142 | //Read values for AIR |
umairaftab | 8:2d462919519e | 143 | |
umairaftab | 8:2d462919519e | 144 | //OUTSIDE |
umairaftab | 8:2d462919519e | 145 | outside_humidity = get_air_humid_outside(); |
umairaftab | 8:2d462919519e | 146 | outside_temp = get_air_temp_outside(temp_unit); |
umairaftab | 8:2d462919519e | 147 | outside_dewpoint = get_air_dewpoint_outside(); |
umairaftab | 8:2d462919519e | 148 | |
umairaftab | 8:2d462919519e | 149 | //INSIDE |
umairaftab | 8:2d462919519e | 150 | inside_humidity = get_air_humid_inside(); |
umairaftab | 8:2d462919519e | 151 | inside_temp = get_air_temp_inside(temp_unit); |
umairaftab | 8:2d462919519e | 152 | inside_dewpoint = get_air_dewpoint_inside(); |
umairaftab | 8:2d462919519e | 153 | |
umairaftab | 8:2d462919519e | 154 | //Read value for soil |
umairaftab | 8:2d462919519e | 155 | read_soil_humidity(); |
umairaftab | 8:2d462919519e | 156 | calc_soil_humid_values(); //values in soil1_humid and soil2_humid perecentages |
umairaftab | 11:f9ffd5ab7e94 | 157 | soil1_humidity = soil1_humid ; |
umairaftab | 11:f9ffd5ab7e94 | 158 | soil2_humidity = soil2_humid ; |
umairaftab | 14:72176f1e4907 | 159 | //printf("%4.2f \n\r",soil1_humidity); |
umairaftab | 14:72176f1e4907 | 160 | //READ LOAD SENSOR |
umairaftab | 14:72176f1e4907 | 161 | read_weight(); |
umairaftab | 14:72176f1e4907 | 162 | calc_weight(); |
umairaftab | 14:72176f1e4907 | 163 | weight_sensor = weight1; |
umairaftab | 8:2d462919519e | 164 | } |
umairaftab | 8:2d462919519e | 165 | |
umairaftab | 8:2d462919519e | 166 | //****************************Functions that perform tasks************************************** |
umairaftab | 37:892872c3fa96 | 167 | //CYCLE AIR |
umairaftab | 37:892872c3fa96 | 168 | void cycleair(){ |
umairaftab | 37:892872c3fa96 | 169 | |
umairaftab | 37:892872c3fa96 | 170 | //Turn on fan |
umairaftab | 37:892872c3fa96 | 171 | cycle_air_on(); |
umairaftab | 37:892872c3fa96 | 172 | wait(CYCLE_AIR_TIME); |
umairaftab | 37:892872c3fa96 | 173 | //turn of fan |
umairaftab | 37:892872c3fa96 | 174 | cycle_air_off(); |
umairaftab | 37:892872c3fa96 | 175 | |
umairaftab | 37:892872c3fa96 | 176 | } |
umairaftab | 9:43c339533f7f | 177 | //Water Plants |
umairaftab | 8:2d462919519e | 178 | void waterplants(){ |
umairaftab | 8:2d462919519e | 179 | |
umairaftab | 8:2d462919519e | 180 | |
umairaftab | 9:43c339533f7f | 181 | if(startup_flag == true){ |
umairaftab | 14:72176f1e4907 | 182 | //call for pump function |
umairaftab | 14:72176f1e4907 | 183 | |
umairaftab | 9:43c339533f7f | 184 | watered_plant1 = true; |
umairaftab | 9:43c339533f7f | 185 | watered_plant1_time = hour ; |
umairaftab | 9:43c339533f7f | 186 | watered_plant2 = true; |
umairaftab | 9:43c339533f7f | 187 | watered_plant2_time = hour ; |
umairaftab | 14:72176f1e4907 | 188 | pumps(true,true,true,false); |
umairaftab | 14:72176f1e4907 | 189 | wait(5.0); |
umairaftab | 14:72176f1e4907 | 190 | pumps(false,false,false,false); |
umairaftab | 9:43c339533f7f | 191 | } |
umairaftab | 9:43c339533f7f | 192 | else{ |
umairaftab | 9:43c339533f7f | 193 | |
umairaftab | 10:1a0fe96381b0 | 194 | if( (soil1_humid < setpoint_soil_humid1) || (watered_plant1 == false) ){ |
umairaftab | 9:43c339533f7f | 195 | //enable pump1 |
umairaftab | 9:43c339533f7f | 196 | watered_plant1 = true; |
umairaftab | 9:43c339533f7f | 197 | watered_plant1_time = hour ; |
umairaftab | 14:72176f1e4907 | 198 | pumps(true,true,true,false); |
umairaftab | 14:72176f1e4907 | 199 | wait(5.0); |
umairaftab | 14:72176f1e4907 | 200 | pumps(false,false,false,false); |
umairaftab | 9:43c339533f7f | 201 | } |
umairaftab | 10:1a0fe96381b0 | 202 | if( (soil2_humid < setpoint_soil_humid2) || (watered_plant2 == false) ){ |
umairaftab | 9:43c339533f7f | 203 | //enable pump2 |
umairaftab | 9:43c339533f7f | 204 | watered_plant2 = true; |
umairaftab | 9:43c339533f7f | 205 | watered_plant2_time = hour ; |
umairaftab | 14:72176f1e4907 | 206 | pumps(true,true,true,false); |
umairaftab | 14:72176f1e4907 | 207 | wait(5.0); |
umairaftab | 14:72176f1e4907 | 208 | pumps(false,false,false,false); |
umairaftab | 9:43c339533f7f | 209 | } |
umairaftab | 9:43c339533f7f | 210 | } |
umairaftab | 10:1a0fe96381b0 | 211 | //Make sure it is watered at least every x hours in case soil humid doesnt work |
umairaftab | 9:43c339533f7f | 212 | if (watered_plant1 == true){ |
umairaftab | 9:43c339533f7f | 213 | if(abs(hour-watered_plant1_time)>MAX_WATERING_TIME_GAP){ |
umairaftab | 9:43c339533f7f | 214 | watered_plant1 = false; |
umairaftab | 37:892872c3fa96 | 215 | cycleair(); |
umairaftab | 9:43c339533f7f | 216 | } |
umairaftab | 9:43c339533f7f | 217 | } |
umairaftab | 9:43c339533f7f | 218 | if (watered_plant2 == true){ |
umairaftab | 9:43c339533f7f | 219 | if(abs(hour-watered_plant2_time)>MAX_WATERING_TIME_GAP){ |
umairaftab | 9:43c339533f7f | 220 | watered_plant2 = false; |
umairaftab | 37:892872c3fa96 | 221 | cycleair(); |
umairaftab | 9:43c339533f7f | 222 | } |
umairaftab | 9:43c339533f7f | 223 | } |
umairaftab | 9:43c339533f7f | 224 | |
umairaftab | 9:43c339533f7f | 225 | } |
umairaftab | 9:43c339533f7f | 226 | |
umairaftab | 9:43c339533f7f | 227 | // Air Humidity Level |
umairaftab | 9:43c339533f7f | 228 | void airhumidity(){ |
umairaftab | 9:43c339533f7f | 229 | |
umairaftab | 11:f9ffd5ab7e94 | 230 | if( !( (setpoint_air_humidity+window_f > inside_humidity) && (setpoint_air_humidity-window_f < inside_humidity) ) ){ |
umairaftab | 9:43c339533f7f | 231 | |
umairaftab | 9:43c339533f7f | 232 | //Turn on Air humidity fan |
umairaftab | 14:72176f1e4907 | 233 | pumps(false,false,false,true); |
umairaftab | 9:43c339533f7f | 234 | wait(5); |
umairaftab | 9:43c339533f7f | 235 | //Turn off Air humisity fan |
umairaftab | 14:72176f1e4907 | 236 | pumps(false,false,false,false); |
umairaftab | 9:43c339533f7f | 237 | } |
umairaftab | 9:43c339533f7f | 238 | } |
umairaftab | 9:43c339533f7f | 239 | |
umairaftab | 37:892872c3fa96 | 240 | |
umairaftab | 14:72176f1e4907 | 241 | //**********************************LCD TIMEOUT FUNCTION********************************* |
umairaftab | 12:b3137bb72ef7 | 242 | void lcd_timeout_check(){ |
umairaftab | 12:b3137bb72ef7 | 243 | |
umairaftab | 12:b3137bb72ef7 | 244 | if(lcd_timeout.read()>LCD_TIMEOUT_VALUE){ |
umairaftab | 12:b3137bb72ef7 | 245 | lcd_timeout_flag = true; |
umairaftab | 12:b3137bb72ef7 | 246 | } |
umairaftab | 12:b3137bb72ef7 | 247 | |
umairaftab | 12:b3137bb72ef7 | 248 | } |
umairaftab | 26:2f59456a7bad | 249 | void settings_submenu(int counter_menu){ |
umairaftab | 26:2f59456a7bad | 250 | |
umairaftab | 26:2f59456a7bad | 251 | char key_value2; |
umairaftab | 26:2f59456a7bad | 252 | bool break_flag = false; |
umairaftab | 26:2f59456a7bad | 253 | switch(counter_menu){ |
umairaftab | 26:2f59456a7bad | 254 | case 0: |
umairaftab | 26:2f59456a7bad | 255 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 256 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 257 | lcd.printf("Not Authorised"); |
umairaftab | 26:2f59456a7bad | 258 | wait(5); |
umairaftab | 26:2f59456a7bad | 259 | break; |
umairaftab | 26:2f59456a7bad | 260 | case 1: |
umairaftab | 26:2f59456a7bad | 261 | break_flag = false; |
umairaftab | 26:2f59456a7bad | 262 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 263 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 264 | lcd.printf("Cur Air Humidity Lvl"); |
umairaftab | 26:2f59456a7bad | 265 | //lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 266 | //lcd.printf("%3.1f",setpoint_air_humidity); |
umairaftab | 26:2f59456a7bad | 267 | while(!break_flag){ |
umairaftab | 26:2f59456a7bad | 268 | lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 269 | lcd.printf("%3.1f",setpoint_air_humidity); |
umairaftab | 26:2f59456a7bad | 270 | key_value2 = Keypad(); |
umairaftab | 26:2f59456a7bad | 271 | wait(0.2); |
umairaftab | 36:ce0ca02a8253 | 272 | if(key_value2 == 74){setpoint_air_humidity++;} |
umairaftab | 36:ce0ca02a8253 | 273 | else if(key_value2 == 71){setpoint_air_humidity--;} |
umairaftab | 26:2f59456a7bad | 274 | else if(key_value2 == 75){break_flag=true;} //enter |
umairaftab | 26:2f59456a7bad | 275 | if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;} |
umairaftab | 26:2f59456a7bad | 276 | } |
umairaftab | 26:2f59456a7bad | 277 | |
umairaftab | 26:2f59456a7bad | 278 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 279 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 280 | lcd.printf("NEW Air Humid Setpoint"); |
umairaftab | 26:2f59456a7bad | 281 | lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 282 | lcd.printf("%3.1f",setpoint_air_humidity); |
umairaftab | 26:2f59456a7bad | 283 | wait(5); |
umairaftab | 26:2f59456a7bad | 284 | |
umairaftab | 26:2f59456a7bad | 285 | break; |
umairaftab | 26:2f59456a7bad | 286 | case 2: |
umairaftab | 26:2f59456a7bad | 287 | break_flag = false; |
umairaftab | 26:2f59456a7bad | 288 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 289 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 290 | lcd.printf("Soil Humidity Setpoint"); |
umairaftab | 26:2f59456a7bad | 291 | |
umairaftab | 26:2f59456a7bad | 292 | while(!break_flag){ |
umairaftab | 26:2f59456a7bad | 293 | lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 294 | lcd.printf("S1: %4.2f",setpoint_soil_humid1); |
umairaftab | 26:2f59456a7bad | 295 | lcd.printf(" S2: %4.2f",setpoint_soil_humid2); |
umairaftab | 26:2f59456a7bad | 296 | key_value2 = Keypad(); |
umairaftab | 26:2f59456a7bad | 297 | wait(0.2); |
umairaftab | 36:ce0ca02a8253 | 298 | if(key_value2 == 62){ //up |
umairaftab | 26:2f59456a7bad | 299 | setpoint_soil_humid1++; |
umairaftab | 26:2f59456a7bad | 300 | setpoint_soil_humid2++; |
umairaftab | 26:2f59456a7bad | 301 | } |
umairaftab | 36:ce0ca02a8253 | 302 | else if(key_value2 == 59){//down |
umairaftab | 26:2f59456a7bad | 303 | setpoint_soil_humid1--; |
umairaftab | 26:2f59456a7bad | 304 | setpoint_soil_humid2--; |
umairaftab | 26:2f59456a7bad | 305 | } |
umairaftab | 26:2f59456a7bad | 306 | else if(key_value2 == 75){break_flag=true;}//enterkey |
umairaftab | 26:2f59456a7bad | 307 | //if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;} |
umairaftab | 26:2f59456a7bad | 308 | } |
umairaftab | 26:2f59456a7bad | 309 | |
umairaftab | 26:2f59456a7bad | 310 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 311 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 312 | lcd.printf("New Soil Setpoints:"); |
umairaftab | 26:2f59456a7bad | 313 | lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 314 | lcd.printf("S1: %4.2f",setpoint_soil_humid1); |
umairaftab | 26:2f59456a7bad | 315 | lcd.printf(" S2: %4.2f",setpoint_soil_humid2); |
umairaftab | 26:2f59456a7bad | 316 | wait(5); |
umairaftab | 26:2f59456a7bad | 317 | break; |
umairaftab | 26:2f59456a7bad | 318 | case 3: |
umairaftab | 26:2f59456a7bad | 319 | |
umairaftab | 26:2f59456a7bad | 320 | break_flag = false; |
umairaftab | 26:2f59456a7bad | 321 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 322 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 323 | lcd.printf("Cur Air Tmp Setpoint"); |
umairaftab | 26:2f59456a7bad | 324 | while(!break_flag){ |
umairaftab | 26:2f59456a7bad | 325 | lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 326 | lcd.printf("%3.1f",setpoint_MAX_air_temp); |
umairaftab | 26:2f59456a7bad | 327 | key_value2 = Keypad(); |
umairaftab | 26:2f59456a7bad | 328 | wait(0.2); |
umairaftab | 36:ce0ca02a8253 | 329 | if(key_value2 == 74){setpoint_MAX_air_temp++;} |
umairaftab | 36:ce0ca02a8253 | 330 | else if(key_value2 == 71){setpoint_MAX_air_temp--;} |
umairaftab | 26:2f59456a7bad | 331 | else if(key_value2 == 75){break_flag=true;} |
umairaftab | 26:2f59456a7bad | 332 | if (setpoint_MAX_air_temp <0 || setpoint_MAX_air_temp >99) {setpoint_MAX_air_temp=45.0;} |
umairaftab | 26:2f59456a7bad | 333 | } |
umairaftab | 26:2f59456a7bad | 334 | |
umairaftab | 26:2f59456a7bad | 335 | lcd.cls(); |
umairaftab | 26:2f59456a7bad | 336 | lcd.locate(0,0); |
umairaftab | 26:2f59456a7bad | 337 | lcd.printf("NEW Air Tmp Setpoint"); |
umairaftab | 26:2f59456a7bad | 338 | lcd.locate(0,1); |
umairaftab | 26:2f59456a7bad | 339 | lcd.printf("%3.1f",setpoint_MAX_air_temp); |
umairaftab | 26:2f59456a7bad | 340 | wait(5); |
umairaftab | 26:2f59456a7bad | 341 | break; |
umairaftab | 26:2f59456a7bad | 342 | }//switch end |
umairaftab | 26:2f59456a7bad | 343 | |
umairaftab | 26:2f59456a7bad | 344 | } |
umairaftab | 14:72176f1e4907 | 345 | //***************************************SETTINGS UI************************************* |
umairaftab | 12:b3137bb72ef7 | 346 | void ui_settings(){ |
umairaftab | 12:b3137bb72ef7 | 347 | |
umairaftab | 12:b3137bb72ef7 | 348 | lcd.cls(); |
umairaftab | 12:b3137bb72ef7 | 349 | lcd.locate(0,0); |
umairaftab | 12:b3137bb72ef7 | 350 | lcd.printf("Autus Settings"); |
umairaftab | 12:b3137bb72ef7 | 351 | lcd.locate(0,1); |
umairaftab | 12:b3137bb72ef7 | 352 | lcd.printf("Performing Checks"); |
umairaftab | 12:b3137bb72ef7 | 353 | char key_value; |
umairaftab | 12:b3137bb72ef7 | 354 | bool exit_settings=false; |
umairaftab | 12:b3137bb72ef7 | 355 | |
umairaftab | 12:b3137bb72ef7 | 356 | //disable peltier |
umairaftab | 14:72176f1e4907 | 357 | peltier(false,false,false,false,0); |
umairaftab | 12:b3137bb72ef7 | 358 | |
umairaftab | 12:b3137bb72ef7 | 359 | wait(2); |
umairaftab | 32:d8b232481ec5 | 360 | string menu[5]; |
umairaftab | 12:b3137bb72ef7 | 361 | menu[0]= "1.LED Brightness"; |
umairaftab | 12:b3137bb72ef7 | 362 | menu[1]= "2.Air Humidty Lvl"; |
umairaftab | 12:b3137bb72ef7 | 363 | menu[2]= "3.Soil Moisture Lvl"; |
umairaftab | 12:b3137bb72ef7 | 364 | menu[3]= "4.Air Temperature"; |
umairaftab | 32:d8b232481ec5 | 365 | menu[4]= " "; |
umairaftab | 12:b3137bb72ef7 | 366 | lcd.cls(); |
umairaftab | 12:b3137bb72ef7 | 367 | int counter_menu =0 ; |
umairaftab | 29:b712f073a397 | 368 | bool overflow_menu = false; |
umairaftab | 12:b3137bb72ef7 | 369 | while(!exit_settings){ |
umairaftab | 26:2f59456a7bad | 370 | |
umairaftab | 12:b3137bb72ef7 | 371 | key_value = Keypad(); |
umairaftab | 35:8bea464c2028 | 372 | printf("Key %d\n\r",key_value); |
umairaftab | 27:24478764d4b2 | 373 | wait(0.1); |
umairaftab | 25:a6d1eaf2041c | 374 | if(key_value == 150){ |
umairaftab | 12:b3137bb72ef7 | 375 | lcd.locate(0,0); |
umairaftab | 12:b3137bb72ef7 | 376 | lcd.printf(">%s",menu[counter_menu].c_str()); |
umairaftab | 12:b3137bb72ef7 | 377 | lcd.locate(0,1); |
umairaftab | 32:d8b232481ec5 | 378 | if(counter_menu ==4){ |
umairaftab | 25:a6d1eaf2041c | 379 | counter_menu = 0; |
umairaftab | 29:b712f073a397 | 380 | overflow_menu=true; |
umairaftab | 25:a6d1eaf2041c | 381 | lcd.printf(" %s",menu[counter_menu].c_str()); |
umairaftab | 12:b3137bb72ef7 | 382 | } |
umairaftab | 12:b3137bb72ef7 | 383 | else{ |
umairaftab | 25:a6d1eaf2041c | 384 | lcd.printf(" %s",menu[counter_menu+1].c_str()); |
umairaftab | 12:b3137bb72ef7 | 385 | } |
umairaftab | 26:2f59456a7bad | 386 | //wait(0.2); |
umairaftab | 12:b3137bb72ef7 | 387 | }//No Press If Block |
umairaftab | 36:ce0ca02a8253 | 388 | else if(key_value == 68){//Down Key Pressed if block |
umairaftab | 12:b3137bb72ef7 | 389 | lcd.cls(); |
umairaftab | 29:b712f073a397 | 390 | if(overflow_menu==false){ |
umairaftab | 32:d8b232481ec5 | 391 | counter_menu++; |
umairaftab | 33:d1b04f1a792a | 392 | //printf("CounterOverflow)"); |
umairaftab | 32:d8b232481ec5 | 393 | } |
umairaftab | 29:b712f073a397 | 394 | else{overflow_menu=false;} |
umairaftab | 32:d8b232481ec5 | 395 | |
umairaftab | 12:b3137bb72ef7 | 396 | }//Down Key Pressed if block end |
umairaftab | 36:ce0ca02a8253 | 397 | else if(key_value == 65){ //OK Key Pressed if block |
umairaftab | 26:2f59456a7bad | 398 | settings_submenu(counter_menu); |
umairaftab | 33:d1b04f1a792a | 399 | lcd.cls(); |
umairaftab | 12:b3137bb72ef7 | 400 | } //OK button if block |
umairaftab | 36:ce0ca02a8253 | 401 | else if(key_value == 75){ //ENTR Button |
umairaftab | 12:b3137bb72ef7 | 402 | exit_settings = true; |
umairaftab | 12:b3137bb72ef7 | 403 | lcd.cls(); |
umairaftab | 12:b3137bb72ef7 | 404 | lcd.printf("SAVE Config"); |
umairaftab | 12:b3137bb72ef7 | 405 | wait(2); |
umairaftab | 12:b3137bb72ef7 | 406 | } |
umairaftab | 12:b3137bb72ef7 | 407 | |
umairaftab | 12:b3137bb72ef7 | 408 | }//While settings loop exit |
umairaftab | 12:b3137bb72ef7 | 409 | lcd.cls(); |
umairaftab | 12:b3137bb72ef7 | 410 | lcd.printf("Exit Settings"); |
umairaftab | 25:a6d1eaf2041c | 411 | wait(5); |
umairaftab | 12:b3137bb72ef7 | 412 | } |
umairaftab | 26:2f59456a7bad | 413 | |
umairaftab | 26:2f59456a7bad | 414 | |
umairaftab | 12:b3137bb72ef7 | 415 | //Function to process keypad inputs |
umairaftab | 12:b3137bb72ef7 | 416 | void process_user_input(char keypad_value_in, int ui_current_screen_in){ |
umairaftab | 12:b3137bb72ef7 | 417 | |
umairaftab | 18:7ec1691d0d9d | 418 | if(keypad_value_in == 61){ |
umairaftab | 12:b3137bb72ef7 | 419 | if(lcd_timeout_flag == false){ |
umairaftab | 12:b3137bb72ef7 | 420 | switch (ui_current_screen_in){ |
umairaftab | 12:b3137bb72ef7 | 421 | case 1: |
umairaftab | 12:b3137bb72ef7 | 422 | ui_screen2(); |
umairaftab | 12:b3137bb72ef7 | 423 | ui_current_screen_in =2; |
umairaftab | 12:b3137bb72ef7 | 424 | break; |
umairaftab | 12:b3137bb72ef7 | 425 | case 2: |
umairaftab | 12:b3137bb72ef7 | 426 | ui_screen3(); |
umairaftab | 12:b3137bb72ef7 | 427 | ui_current_screen_in =3; |
umairaftab | 12:b3137bb72ef7 | 428 | break; |
umairaftab | 12:b3137bb72ef7 | 429 | case 3: |
umairaftab | 12:b3137bb72ef7 | 430 | ui_screen4(); |
umairaftab | 12:b3137bb72ef7 | 431 | ui_current_screen_in =4; |
umairaftab | 12:b3137bb72ef7 | 432 | break; |
umairaftab | 12:b3137bb72ef7 | 433 | }//switch block current ui screen |
umairaftab | 12:b3137bb72ef7 | 434 | lcd_timeout.reset(); |
umairaftab | 12:b3137bb72ef7 | 435 | lcd_timeout.start(); |
umairaftab | 12:b3137bb72ef7 | 436 | wait(2); |
umairaftab | 12:b3137bb72ef7 | 437 | }// if block lcdflag |
umairaftab | 12:b3137bb72ef7 | 438 | else{ |
umairaftab | 12:b3137bb72ef7 | 439 | ui_screen1(); |
umairaftab | 12:b3137bb72ef7 | 440 | wait(5); |
umairaftab | 12:b3137bb72ef7 | 441 | } |
umairaftab | 12:b3137bb72ef7 | 442 | }// if block 36 end |
umairaftab | 12:b3137bb72ef7 | 443 | |
umairaftab | 12:b3137bb72ef7 | 444 | // check for setting screen press enter |
umairaftab | 18:7ec1691d0d9d | 445 | if(keypad_value_in == 58){ |
umairaftab | 12:b3137bb72ef7 | 446 | //Disable peltier |
umairaftab | 12:b3137bb72ef7 | 447 | ui_settings(); |
umairaftab | 12:b3137bb72ef7 | 448 | wait(5); |
umairaftab | 12:b3137bb72ef7 | 449 | } |
umairaftab | 14:72176f1e4907 | 450 | |
umairaftab | 14:72176f1e4907 | 451 | if(keypad_value_in ==100){ |
umairaftab | 14:72176f1e4907 | 452 | ui_screen1(); |
umairaftab | 17:0ff7385db570 | 453 | wait(0.2); |
umairaftab | 14:72176f1e4907 | 454 | } |
umairaftab | 12:b3137bb72ef7 | 455 | } |
umairaftab | 12:b3137bb72ef7 | 456 | |
umairaftab | 12:b3137bb72ef7 | 457 | |
umairaftab | 12:b3137bb72ef7 | 458 | |
umairaftab | 12:b3137bb72ef7 | 459 | |
umairaftab | 8:2d462919519e | 460 | //***************************PLACEHOLDER FUNCTION TO DISABLE EVERYTHING ********************** |
umairaftab | 8:2d462919519e | 461 | void disable_everything(){ |
umairaftab | 8:2d462919519e | 462 | |
umairaftab | 10:1a0fe96381b0 | 463 | //Disable peltier,vac,fans,pumps,lights. |
umairaftab | 14:72176f1e4907 | 464 | pumps(false,false,false,false); |
umairaftab | 14:72176f1e4907 | 465 | peltier(false,false,false,false,0); |
umairaftab | 37:892872c3fa96 | 466 | cycle_air_off(); |
umairaftab | 8:2d462919519e | 467 | } |
umairaftab | 8:2d462919519e | 468 | |
umairaftab | 8:2d462919519e | 469 | |
umairaftab | 8:2d462919519e | 470 | //********************************************************************************************* |
umairaftab | 8:2d462919519e | 471 | //* * |
umairaftab | 8:2d462919519e | 472 | //* * |
umairaftab | 8:2d462919519e | 473 | //* * |
umairaftab | 8:2d462919519e | 474 | //* * |
umairaftab | 8:2d462919519e | 475 | //* MAIN ROUTINE * |
umairaftab | 8:2d462919519e | 476 | //* * |
umairaftab | 8:2d462919519e | 477 | //* DO NOT MODIFY WITHOUT TELLING UMAIR * |
umairaftab | 8:2d462919519e | 478 | //* * |
umairaftab | 8:2d462919519e | 479 | //* * |
umairaftab | 8:2d462919519e | 480 | //********************************************************************************************* |
umairaftab | 1:9ef26efedcea | 481 | |
umairaftab | 1:9ef26efedcea | 482 | int main(void) |
umairaftab | 1:9ef26efedcea | 483 | { |
umairaftab | 8:2d462919519e | 484 | |
umairaftab | 8:2d462919519e | 485 | //call function that disables everything. |
umairaftab | 8:2d462919519e | 486 | disable_everything(); |
umairaftab | 8:2d462919519e | 487 | |
umairaftab | 8:2d462919519e | 488 | |
umairaftab | 31:a90b72ae9835 | 489 | lcd_backlight_on(); |
umairaftab | 8:2d462919519e | 490 | //FOR INTERNAL CLOCK |
umairaftab | 33:d1b04f1a792a | 491 | clock_mine.attach(&sec_inc, 1.0); |
umairaftab | 36:ce0ca02a8253 | 492 | |
umairaftab | 8:2d462919519e | 493 | char keypad_value; |
umairaftab | 11:f9ffd5ab7e94 | 494 | int ui_current_screen = 1; |
umairaftab | 10:1a0fe96381b0 | 495 | //************************************BOOT SEQUENCE********************* |
umairaftab | 8:2d462919519e | 496 | //call LCD boot |
umairaftab | 8:2d462919519e | 497 | ui_startup(); |
umairaftab | 9:43c339533f7f | 498 | wait(2); |
umairaftab | 8:2d462919519e | 499 | //SET TIME |
umairaftab | 8:2d462919519e | 500 | rtcimp_settime(6,0); |
umairaftab | 8:2d462919519e | 501 | //call function that reads values |
umairaftab | 9:43c339533f7f | 502 | |
umairaftab | 9:43c339533f7f | 503 | /* FOR CRTITICALITY |
umairaftab | 9:43c339533f7f | 504 | NVIC_DisableIRQ(TIMER3_IRQn); |
umairaftab | 9:43c339533f7f | 505 | |
umairaftab | 9:43c339533f7f | 506 | // critical section |
umairaftab | 9:43c339533f7f | 507 | |
umairaftab | 9:43c339533f7f | 508 | NVIC_EnableIRQ(TIMER3_IRQn); |
umairaftab | 38:9f4107db1bff | 509 | */ wait(5); |
umairaftab | 38:9f4107db1bff | 510 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 511 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 512 | lcd.printf("Find Pelt Temp Sense"); |
umairaftab | 38:9f4107db1bff | 513 | |
umairaftab | 44:083a8de27bd9 | 514 | tempinit(); |
umairaftab | 42:41f6c241a987 | 515 | //peltierin_temp = dsen_temp_in; |
umairaftab | 42:41f6c241a987 | 516 | //peltierout_temp = dsen_temp_out; |
umairaftab | 38:9f4107db1bff | 517 | |
umairaftab | 38:9f4107db1bff | 518 | wait(2); |
umairaftab | 38:9f4107db1bff | 519 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 520 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 521 | lcd.printf("Find Pelt Temp Sense"); |
umairaftab | 38:9f4107db1bff | 522 | lcd.printf("Found Them"); |
umairaftab | 38:9f4107db1bff | 523 | |
umairaftab | 38:9f4107db1bff | 524 | wait(2); |
umairaftab | 9:43c339533f7f | 525 | lcd.cls(); |
umairaftab | 9:43c339533f7f | 526 | lcd.locate(0,0); |
umairaftab | 9:43c339533f7f | 527 | lcd.printf("Reading Sensors"); |
umairaftab | 9:43c339533f7f | 528 | |
umairaftab | 8:2d462919519e | 529 | read_sensors(); |
umairaftab | 8:2d462919519e | 530 | |
umairaftab | 9:43c339533f7f | 531 | wait(2); |
umairaftab | 9:43c339533f7f | 532 | lcd.cls(); |
umairaftab | 9:43c339533f7f | 533 | lcd.locate(0,0); |
umairaftab | 9:43c339533f7f | 534 | lcd.printf("Done Reading Sensors"); |
umairaftab | 8:2d462919519e | 535 | //call function that performs functions. |
umairaftab | 8:2d462919519e | 536 | |
umairaftab | 9:43c339533f7f | 537 | wait(2); |
umairaftab | 9:43c339533f7f | 538 | lcd.cls(); |
umairaftab | 9:43c339533f7f | 539 | lcd.locate(0,0); |
umairaftab | 9:43c339533f7f | 540 | lcd.printf("Watering Plants"); |
umairaftab | 57:7ab93ed49b70 | 541 | wait(1); |
umairaftab | 9:43c339533f7f | 542 | |
umairaftab | 38:9f4107db1bff | 543 | waterplants(); |
umairaftab | 9:43c339533f7f | 544 | |
umairaftab | 9:43c339533f7f | 545 | wait(2); |
umairaftab | 9:43c339533f7f | 546 | lcd.cls(); |
umairaftab | 9:43c339533f7f | 547 | lcd.locate(0,0); |
umairaftab | 9:43c339533f7f | 548 | lcd.printf("Air Humidity"); |
umairaftab | 9:43c339533f7f | 549 | |
umairaftab | 37:892872c3fa96 | 550 | airhumidity(); |
umairaftab | 9:43c339533f7f | 551 | |
umairaftab | 9:43c339533f7f | 552 | wait(2); |
umairaftab | 9:43c339533f7f | 553 | lcd.cls(); |
umairaftab | 9:43c339533f7f | 554 | lcd.locate(0,0); |
umairaftab | 9:43c339533f7f | 555 | lcd.printf("Cycling Air"); |
umairaftab | 9:43c339533f7f | 556 | |
umairaftab | 9:43c339533f7f | 557 | cycleair(); |
umairaftab | 9:43c339533f7f | 558 | |
umairaftab | 11:f9ffd5ab7e94 | 559 | wait(2); |
umairaftab | 11:f9ffd5ab7e94 | 560 | lcd.cls(); |
umairaftab | 11:f9ffd5ab7e94 | 561 | lcd.locate(0,0); |
umairaftab | 11:f9ffd5ab7e94 | 562 | lcd.printf("Testing Lights"); |
umairaftab | 37:892872c3fa96 | 563 | led_test(); |
umairaftab | 11:f9ffd5ab7e94 | 564 | |
umairaftab | 11:f9ffd5ab7e94 | 565 | |
umairaftab | 36:ce0ca02a8253 | 566 | //INTILIZE SERIAL PARAMETERS |
umairaftab | 36:ce0ca02a8253 | 567 | wait(2); |
umairaftab | 36:ce0ca02a8253 | 568 | lcd.cls(); |
umairaftab | 36:ce0ca02a8253 | 569 | lcd.locate(0,0); |
umairaftab | 36:ce0ca02a8253 | 570 | lcd.printf("Initialize Bluetooth"); |
umairaftab | 36:ce0ca02a8253 | 571 | bluetooth_dev.baud(9600); |
umairaftab | 36:ce0ca02a8253 | 572 | bluetooth_dev.attach(&callback_bluetooth); |
umairaftab | 36:ce0ca02a8253 | 573 | |
umairaftab | 54:1302a97c84aa | 574 | wait(2); |
umairaftab | 54:1302a97c84aa | 575 | lcd.cls(); |
umairaftab | 54:1302a97c84aa | 576 | lcd.locate(0,0); |
umairaftab | 54:1302a97c84aa | 577 | lcd.printf("Initialize Printer"); |
umairaftab | 54:1302a97c84aa | 578 | printer.baud(BAUDRATE0); |
umairaftab | 54:1302a97c84aa | 579 | printer.format(8,Serial::None,1); |
umairaftab | 54:1302a97c84aa | 580 | printer.printf("Autus Ready\n\r"); |
umairaftab | 54:1302a97c84aa | 581 | //printer_print_values(); |
umairaftab | 9:43c339533f7f | 582 | wait(5); |
umairaftab | 36:ce0ca02a8253 | 583 | lcd.cls(); |
umairaftab | 12:b3137bb72ef7 | 584 | ui_current_screen = 1; |
umairaftab | 9:43c339533f7f | 585 | ui_screen1(); |
umairaftab | 12:b3137bb72ef7 | 586 | lcd_timeout.reset(); |
umairaftab | 9:43c339533f7f | 587 | wait(5); |
umairaftab | 8:2d462919519e | 588 | |
umairaftab | 37:892872c3fa96 | 589 | //startup_flag = false ; |
umairaftab | 14:72176f1e4907 | 590 | timer1ms.attach(&timer1, 0.001); //interrupt attached function(timer) with interval (1 ms) |
umairaftab | 25:a6d1eaf2041c | 591 | led_blue_pulsewidth=50; |
umairaftab | 25:a6d1eaf2041c | 592 | led_blue.period_us(1000); |
umairaftab | 25:a6d1eaf2041c | 593 | |
umairaftab | 1:9ef26efedcea | 594 | while(1) { |
umairaftab | 8:2d462919519e | 595 | |
umairaftab | 14:72176f1e4907 | 596 | |
umairaftab | 9:43c339533f7f | 597 | //FOR BUZZER |
umairaftab | 14:72176f1e4907 | 598 | |
umairaftab | 8:2d462919519e | 599 | keypad_value = Keypad(); |
umairaftab | 17:0ff7385db570 | 600 | wait(0.1); |
umairaftab | 25:a6d1eaf2041c | 601 | |
umairaftab | 19:4313ad838fef | 602 | //lcd_timeout_check(); |
umairaftab | 19:4313ad838fef | 603 | //process_user_input(keypad_value,ui_current_screen); |
umairaftab | 25:a6d1eaf2041c | 604 | |
umairaftab | 36:ce0ca02a8253 | 605 | //Press down arrow to change menu |
umairaftab | 36:ce0ca02a8253 | 606 | if ( (keypad_value==68) && (ui_current_screen==1) ) { |
umairaftab | 19:4313ad838fef | 607 | ui_screen2(); |
umairaftab | 25:a6d1eaf2041c | 608 | ui_current_screen=2; |
umairaftab | 22:7a1962d8af68 | 609 | wait(5); |
umairaftab | 33:d1b04f1a792a | 610 | lcd.cls(); |
umairaftab | 25:a6d1eaf2041c | 611 | //led_blue_pulsewidth=led_blue_pulsewidth+100; |
umairaftab | 25:a6d1eaf2041c | 612 | //led_blue.pulsewidth_us(led_blue_pulsewidth); |
umairaftab | 25:a6d1eaf2041c | 613 | //printf("%c\n\r",keypad_value); |
umairaftab | 19:4313ad838fef | 614 | } |
umairaftab | 36:ce0ca02a8253 | 615 | else if ( (keypad_value==68) && (ui_current_screen==2)) { |
umairaftab | 19:4313ad838fef | 616 | ui_screen3(); |
umairaftab | 33:d1b04f1a792a | 617 | ui_current_screen=3; |
umairaftab | 22:7a1962d8af68 | 618 | wait(5); |
umairaftab | 33:d1b04f1a792a | 619 | lcd.cls(); |
umairaftab | 25:a6d1eaf2041c | 620 | //printf("%c\n\r",keypad_value); |
umairaftab | 25:a6d1eaf2041c | 621 | } |
umairaftab | 36:ce0ca02a8253 | 622 | else if ( (keypad_value==68) && (ui_current_screen==3)) { |
umairaftab | 37:892872c3fa96 | 623 | red_light_value = MAX_RED_LIGHT; |
umairaftab | 37:892872c3fa96 | 624 | blue_light_value = MAX_BLUE_LIGHT; |
umairaftab | 37:892872c3fa96 | 625 | green_light_value = MAX_GREEN_LIGHT; |
umairaftab | 25:a6d1eaf2041c | 626 | ui_screen4(); |
umairaftab | 25:a6d1eaf2041c | 627 | ui_current_screen=1; |
umairaftab | 25:a6d1eaf2041c | 628 | wait(5); |
umairaftab | 33:d1b04f1a792a | 629 | lcd.cls(); |
umairaftab | 25:a6d1eaf2041c | 630 | //printf("%c\n\r",keypad_value); |
umairaftab | 25:a6d1eaf2041c | 631 | } |
umairaftab | 36:ce0ca02a8253 | 632 | else if ( (keypad_value==75) ) { //Press Enter for settings |
umairaftab | 25:a6d1eaf2041c | 633 | ui_settings(); |
umairaftab | 25:a6d1eaf2041c | 634 | ui_current_screen=1; |
umairaftab | 33:d1b04f1a792a | 635 | lcd.cls(); |
umairaftab | 25:a6d1eaf2041c | 636 | //wait(5); |
umairaftab | 25:a6d1eaf2041c | 637 | //printf("%c\n\r",keypad_value); |
umairaftab | 19:4313ad838fef | 638 | } |
umairaftab | 46:302da7b90cba | 639 | else if(keypad_value == 73){ |
umairaftab | 46:302da7b90cba | 640 | if(MAX_RED_LIGHT<100){ |
umairaftab | 46:302da7b90cba | 641 | MAX_RED_LIGHT++; |
umairaftab | 46:302da7b90cba | 642 | pwm_red_led(1); |
umairaftab | 46:302da7b90cba | 643 | } |
umairaftab | 46:302da7b90cba | 644 | } |
umairaftab | 46:302da7b90cba | 645 | else if(keypad_value == 70){ |
umairaftab | 46:302da7b90cba | 646 | if(MAX_RED_LIGHT>0){ |
umairaftab | 46:302da7b90cba | 647 | MAX_RED_LIGHT--; |
umairaftab | 46:302da7b90cba | 648 | pwm_red_led(0); |
umairaftab | 46:302da7b90cba | 649 | } |
umairaftab | 46:302da7b90cba | 650 | } |
umairaftab | 46:302da7b90cba | 651 | else if(keypad_value == 67){ |
umairaftab | 46:302da7b90cba | 652 | if(MAX_GREEN_LIGHT<100){ |
umairaftab | 46:302da7b90cba | 653 | MAX_GREEN_LIGHT++; |
umairaftab | 46:302da7b90cba | 654 | pwm_green_led(1); |
umairaftab | 46:302da7b90cba | 655 | } |
umairaftab | 46:302da7b90cba | 656 | } |
umairaftab | 46:302da7b90cba | 657 | else if(keypad_value == 64){ |
umairaftab | 46:302da7b90cba | 658 | if(MAX_GREEN_LIGHT>0){ |
umairaftab | 46:302da7b90cba | 659 | MAX_GREEN_LIGHT--; |
umairaftab | 46:302da7b90cba | 660 | pwm_green_led(0); |
umairaftab | 46:302da7b90cba | 661 | } |
umairaftab | 46:302da7b90cba | 662 | } |
umairaftab | 46:302da7b90cba | 663 | else if(keypad_value == 61){ |
umairaftab | 46:302da7b90cba | 664 | if(MAX_BLUE_LIGHT<100){ |
umairaftab | 46:302da7b90cba | 665 | MAX_BLUE_LIGHT++; |
umairaftab | 46:302da7b90cba | 666 | pwm_blue_led(1); |
umairaftab | 46:302da7b90cba | 667 | } |
umairaftab | 46:302da7b90cba | 668 | } |
umairaftab | 46:302da7b90cba | 669 | else if(keypad_value == 58){ |
umairaftab | 46:302da7b90cba | 670 | if(MAX_BLUE_LIGHT>0){ |
umairaftab | 46:302da7b90cba | 671 | MAX_BLUE_LIGHT--; |
umairaftab | 46:302da7b90cba | 672 | pwm_blue_led(0); |
umairaftab | 46:302da7b90cba | 673 | } |
umairaftab | 46:302da7b90cba | 674 | } |
umairaftab | 19:4313ad838fef | 675 | else { |
umairaftab | 19:4313ad838fef | 676 | ui_screen1(); |
umairaftab | 25:a6d1eaf2041c | 677 | wait(0.1); |
umairaftab | 19:4313ad838fef | 678 | } |
umairaftab | 30:417e8ba439ff | 679 | |
umairaftab | 46:302da7b90cba | 680 | if (keypad_value == 62 ){ //Backlight red up |
umairaftab | 30:417e8ba439ff | 681 | lcd_backlight_on(); |
umairaftab | 30:417e8ba439ff | 682 | } |
umairaftab | 46:302da7b90cba | 683 | if (keypad_value == 59 ){ //Backlight red down |
umairaftab | 30:417e8ba439ff | 684 | lcd_backlight_off(); |
umairaftab | 30:417e8ba439ff | 685 | } |
umairaftab | 38:9f4107db1bff | 686 | if(keypad_value == 84){ |
umairaftab | 38:9f4107db1bff | 687 | pelt_keypad_enable=true; |
umairaftab | 38:9f4107db1bff | 688 | } |
umairaftab | 54:1302a97c84aa | 689 | if(keypad_value == 78){ |
umairaftab | 54:1302a97c84aa | 690 | printer_print_values(); |
umairaftab | 54:1302a97c84aa | 691 | } |
umairaftab | 57:7ab93ed49b70 | 692 | if(keypad_value ==86){ |
umairaftab | 57:7ab93ed49b70 | 693 | pumps(true,false,false,false); |
umairaftab | 57:7ab93ed49b70 | 694 | wait(2); |
umairaftab | 57:7ab93ed49b70 | 695 | pumps(false,false,false,false); |
umairaftab | 57:7ab93ed49b70 | 696 | } |
umairaftab | 57:7ab93ed49b70 | 697 | if(keypad_value ==80){ |
umairaftab | 57:7ab93ed49b70 | 698 | pumps(false,true,true,false); |
umairaftab | 57:7ab93ed49b70 | 699 | wait(2); |
umairaftab | 57:7ab93ed49b70 | 700 | pumps(false,false,false,false); |
umairaftab | 57:7ab93ed49b70 | 701 | } |
umairaftab | 57:7ab93ed49b70 | 702 | if(keypad_value ==83){ |
umairaftab | 57:7ab93ed49b70 | 703 | pumps(false,false,false,true); |
umairaftab | 57:7ab93ed49b70 | 704 | wait(2); |
umairaftab | 57:7ab93ed49b70 | 705 | pumps(false,false,false,false); |
umairaftab | 57:7ab93ed49b70 | 706 | } |
umairaftab | 57:7ab93ed49b70 | 707 | if(keypad_value ==77){ |
umairaftab | 57:7ab93ed49b70 | 708 | cycle_air_on(); |
umairaftab | 57:7ab93ed49b70 | 709 | wait(2); |
umairaftab | 57:7ab93ed49b70 | 710 | cycle_air_off(); |
umairaftab | 57:7ab93ed49b70 | 711 | } |
umairaftab | 53:12b7f7b23a31 | 712 | //printf("%d\n\r",keypad_value); |
umairaftab | 12:b3137bb72ef7 | 713 | // -> Key pressed |
umairaftab | 11:f9ffd5ab7e94 | 714 | |
umairaftab | 38:9f4107db1bff | 715 | |
umairaftab | 37:892872c3fa96 | 716 | //LEDS Timeout functions |
umairaftab | 37:892872c3fa96 | 717 | if(led_set_flag == false){ |
umairaftab | 37:892872c3fa96 | 718 | if( (abs(hour-led_off_time) > led_lights_timeout)||lights_startup_flag ==true){ |
umairaftab | 37:892872c3fa96 | 719 | // printf("MINON%d\n\r",::min); |
umairaftab | 37:892872c3fa96 | 720 | set_leds(); |
umairaftab | 37:892872c3fa96 | 721 | led_set_time = hour; |
umairaftab | 37:892872c3fa96 | 722 | lights_startup_flag = false; |
umairaftab | 37:892872c3fa96 | 723 | // printf("SETLEDS\n\r"); |
umairaftab | 37:892872c3fa96 | 724 | } |
umairaftab | 37:892872c3fa96 | 725 | |
umairaftab | 37:892872c3fa96 | 726 | } |
umairaftab | 37:892872c3fa96 | 727 | if(led_set_flag ==true){ |
umairaftab | 37:892872c3fa96 | 728 | if(abs(hour-led_set_time) > led_lights_timeout){ |
umairaftab | 37:892872c3fa96 | 729 | // printf("MINOFF %d\n\r",::min); |
umairaftab | 37:892872c3fa96 | 730 | turn_off_leds(); |
umairaftab | 37:892872c3fa96 | 731 | led_off_time = hour; |
umairaftab | 37:892872c3fa96 | 732 | led_set_flag =false; |
umairaftab | 37:892872c3fa96 | 733 | // printf("OFF\n\r"); |
umairaftab | 37:892872c3fa96 | 734 | } |
umairaftab | 37:892872c3fa96 | 735 | } |
umairaftab | 37:892872c3fa96 | 736 | //printf("MINOFF %d\n\r",::min); |
umairaftab | 38:9f4107db1bff | 737 | if( (abs((::min)-sensor_function_call_time) > sensor_function_call_timeout) || startup_flag==true){ |
umairaftab | 37:892872c3fa96 | 738 | lcd.cls(); |
umairaftab | 37:892872c3fa96 | 739 | lcd.locate(0,0); |
umairaftab | 37:892872c3fa96 | 740 | lcd.printf("Updating Values"); |
umairaftab | 37:892872c3fa96 | 741 | lcd.locate(0,1); |
umairaftab | 37:892872c3fa96 | 742 | lcd.printf("Performing func"); |
umairaftab | 37:892872c3fa96 | 743 | read_sensors(); |
umairaftab | 37:892872c3fa96 | 744 | airhumidity(); |
umairaftab | 38:9f4107db1bff | 745 | peltierin_temp = dsen_temp_in; |
umairaftab | 38:9f4107db1bff | 746 | peltierout_temp = dsen_temp_out; |
umairaftab | 37:892872c3fa96 | 747 | sensor_function_call_time=::min; |
umairaftab | 54:1302a97c84aa | 748 | printer_print_values(); |
umairaftab | 37:892872c3fa96 | 749 | lcd.cls(); |
umairaftab | 37:892872c3fa96 | 750 | } |
umairaftab | 38:9f4107db1bff | 751 | /**********************PELTIER CALLER************************************************************************/ |
umairaftab | 48:d83dc70e00a8 | 752 | //pelt_keypad_enable = true; |
umairaftab | 40:28d1814d367e | 753 | if (pelt_keypad_enable == true){ |
umairaftab | 38:9f4107db1bff | 754 | if ( ( abs( (::min)-pelt_call_time ) > pelt_call_timeout ) || pelt_first_time == true) { |
umairaftab | 38:9f4107db1bff | 755 | |
umairaftab | 38:9f4107db1bff | 756 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 757 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 758 | lcd.printf("Adjusting Temperature"); |
umairaftab | 38:9f4107db1bff | 759 | lcd.locate(0,1); |
umairaftab | 38:9f4107db1bff | 760 | lcd.printf("Pelt Functions"); |
umairaftab | 40:28d1814d367e | 761 | wait(2); |
umairaftab | 42:41f6c241a987 | 762 | //lcd.cls(); |
umairaftab | 42:41f6c241a987 | 763 | //wait(5); |
umairaftab | 42:41f6c241a987 | 764 | |
umairaftab | 42:41f6c241a987 | 765 | lcd.cls(); |
umairaftab | 42:41f6c241a987 | 766 | lcd.locate(0,0); |
umairaftab | 42:41f6c241a987 | 767 | lcd.printf("Find Pelt Temp Sense"); |
umairaftab | 42:41f6c241a987 | 768 | |
umairaftab | 44:083a8de27bd9 | 769 | //tempinit(); |
umairaftab | 44:083a8de27bd9 | 770 | readTemp(1); |
umairaftab | 44:083a8de27bd9 | 771 | dsen_temp_in=temp; |
umairaftab | 44:083a8de27bd9 | 772 | readTemp(0); |
umairaftab | 44:083a8de27bd9 | 773 | dsen_temp_out=temp; |
umairaftab | 44:083a8de27bd9 | 774 | printf("Pi%2.1f Po%2.1f\n\r",dsen_temp_in,dsen_temp_out); |
umairaftab | 42:41f6c241a987 | 775 | peltierin_temp = dsen_temp_in; |
umairaftab | 42:41f6c241a987 | 776 | peltierout_temp = dsen_temp_out; |
umairaftab | 42:41f6c241a987 | 777 | |
umairaftab | 45:ad99cb94f685 | 778 | wait(5); |
umairaftab | 42:41f6c241a987 | 779 | lcd.cls(); |
umairaftab | 42:41f6c241a987 | 780 | lcd.locate(0,0); |
umairaftab | 42:41f6c241a987 | 781 | lcd.printf("Find Pelt Temp Sense"); |
umairaftab | 42:41f6c241a987 | 782 | lcd.printf("Found Them"); |
umairaftab | 42:41f6c241a987 | 783 | wait(2); |
umairaftab | 41:f484ea386062 | 784 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 785 | pelt_first_time = false ; |
umairaftab | 38:9f4107db1bff | 786 | |
umairaftab | 38:9f4107db1bff | 787 | float pelt_inside_temp =0; |
umairaftab | 38:9f4107db1bff | 788 | bool exit_pelt = false; |
umairaftab | 57:7ab93ed49b70 | 789 | float dsen_temp_out_prev=0; |
umairaftab | 38:9f4107db1bff | 790 | pelt_inside_temp = get_air_temp_inside(0); |
umairaftab | 49:76c1bfa8423b | 791 | bool read_temp1_valid=false; |
umairaftab | 49:76c1bfa8423b | 792 | bool read_temp2_valid=false; |
umairaftab | 57:7ab93ed49b70 | 793 | |
umairaftab | 57:7ab93ed49b70 | 794 | while(!read_temp2_valid){ |
umairaftab | 57:7ab93ed49b70 | 795 | readTemp(0); |
umairaftab | 57:7ab93ed49b70 | 796 | wait(0.1); |
umairaftab | 57:7ab93ed49b70 | 797 | if(temp>0){ |
umairaftab | 57:7ab93ed49b70 | 798 | read_temp2_valid = true; |
umairaftab | 57:7ab93ed49b70 | 799 | } |
umairaftab | 57:7ab93ed49b70 | 800 | } |
umairaftab | 57:7ab93ed49b70 | 801 | //readTemp(0); |
umairaftab | 57:7ab93ed49b70 | 802 | dsen_temp_out_prev=temp; |
umairaftab | 38:9f4107db1bff | 803 | while (exit_pelt == false){ |
umairaftab | 38:9f4107db1bff | 804 | |
umairaftab | 38:9f4107db1bff | 805 | pelt_inside_temp = get_air_temp_inside(0); |
umairaftab | 38:9f4107db1bff | 806 | |
umairaftab | 38:9f4107db1bff | 807 | if (dsen_temp_in<desire_temp) { |
umairaftab | 49:76c1bfa8423b | 808 | read_temp1_valid=false; |
umairaftab | 49:76c1bfa8423b | 809 | read_temp2_valid=false; |
umairaftab | 38:9f4107db1bff | 810 | peltier(true,true,false,true,90); |
umairaftab | 49:76c1bfa8423b | 811 | |
umairaftab | 49:76c1bfa8423b | 812 | //wait(0.1); |
umairaftab | 49:76c1bfa8423b | 813 | while(!read_temp1_valid){ |
umairaftab | 49:76c1bfa8423b | 814 | readTemp(1); |
umairaftab | 49:76c1bfa8423b | 815 | wait(0.1); |
umairaftab | 49:76c1bfa8423b | 816 | if(temp>0){ |
umairaftab | 49:76c1bfa8423b | 817 | read_temp1_valid = true; |
umairaftab | 49:76c1bfa8423b | 818 | } |
umairaftab | 49:76c1bfa8423b | 819 | } |
umairaftab | 45:ad99cb94f685 | 820 | dsen_temp_in=temp; |
umairaftab | 49:76c1bfa8423b | 821 | printf("Inside Temp:%2.1f\n\r",dsen_temp_in); |
umairaftab | 51:8bbe178047a9 | 822 | /*while(!read_temp2_valid){ |
umairaftab | 49:76c1bfa8423b | 823 | readTemp(0); |
umairaftab | 49:76c1bfa8423b | 824 | wait(0.1); |
umairaftab | 49:76c1bfa8423b | 825 | if(temp>0){ |
umairaftab | 49:76c1bfa8423b | 826 | read_temp2_valid = true; |
umairaftab | 49:76c1bfa8423b | 827 | } |
umairaftab | 51:8bbe178047a9 | 828 | }*/ |
umairaftab | 51:8bbe178047a9 | 829 | readTemp(0); |
umairaftab | 45:ad99cb94f685 | 830 | dsen_temp_out=temp; |
umairaftab | 49:76c1bfa8423b | 831 | printf("Outside Temp:%2.1f\n\r",dsen_temp_out); |
umairaftab | 38:9f4107db1bff | 832 | } |
umairaftab | 38:9f4107db1bff | 833 | if (dsen_temp_in>=desire_temp) { |
umairaftab | 57:7ab93ed49b70 | 834 | |
umairaftab | 52:8f863cb2cbae | 835 | read_temp1_valid=false; |
umairaftab | 52:8f863cb2cbae | 836 | read_temp2_valid=false; |
umairaftab | 38:9f4107db1bff | 837 | peltier(true,true,false,true,0); |
umairaftab | 49:76c1bfa8423b | 838 | //wait(0.1); |
umairaftab | 49:76c1bfa8423b | 839 | while(!read_temp1_valid){ |
umairaftab | 49:76c1bfa8423b | 840 | readTemp(1); |
umairaftab | 49:76c1bfa8423b | 841 | wait(0.1); |
umairaftab | 49:76c1bfa8423b | 842 | if(temp>0){ |
umairaftab | 49:76c1bfa8423b | 843 | read_temp1_valid = true; |
umairaftab | 49:76c1bfa8423b | 844 | } |
umairaftab | 49:76c1bfa8423b | 845 | } |
umairaftab | 45:ad99cb94f685 | 846 | dsen_temp_in=temp; |
umairaftab | 49:76c1bfa8423b | 847 | printf("Inside Temp:%2.1f\n\r",dsen_temp_in); |
umairaftab | 51:8bbe178047a9 | 848 | /*while(!read_temp2_valid){ |
umairaftab | 49:76c1bfa8423b | 849 | readTemp(0); |
umairaftab | 49:76c1bfa8423b | 850 | wait(0.1); |
umairaftab | 49:76c1bfa8423b | 851 | if(temp>0){ |
umairaftab | 49:76c1bfa8423b | 852 | read_temp2_valid = true; |
umairaftab | 49:76c1bfa8423b | 853 | } |
umairaftab | 51:8bbe178047a9 | 854 | }*/ |
umairaftab | 51:8bbe178047a9 | 855 | readTemp(0); |
umairaftab | 45:ad99cb94f685 | 856 | dsen_temp_out=temp; |
umairaftab | 49:76c1bfa8423b | 857 | printf("Outside Temp:%2.1f\n\r",dsen_temp_out); |
umairaftab | 38:9f4107db1bff | 858 | } |
umairaftab | 38:9f4107db1bff | 859 | if (dsen_temp_in>=max_peltier_temp){ |
umairaftab | 38:9f4107db1bff | 860 | |
umairaftab | 38:9f4107db1bff | 861 | peltier(false,false,false,false,0); |
umairaftab | 38:9f4107db1bff | 862 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 863 | lcd.printf("Pelt TEMP LIMIT"); |
umairaftab | 38:9f4107db1bff | 864 | lcd.locate(0,1); |
umairaftab | 57:7ab93ed49b70 | 865 | lcd.printf("Pin:%2.1 Pout:%2.1f",dsen_temp_in,dsen_temp_out); |
umairaftab | 38:9f4107db1bff | 866 | exit_pelt = true; |
umairaftab | 38:9f4107db1bff | 867 | pelt_overheat = true; |
umairaftab | 38:9f4107db1bff | 868 | } |
umairaftab | 38:9f4107db1bff | 869 | else{ |
umairaftab | 53:12b7f7b23a31 | 870 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 871 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 872 | lcd.printf("Air Temp %4.2f",pelt_inside_temp); |
umairaftab | 38:9f4107db1bff | 873 | lcd.locate(0,1); |
umairaftab | 57:7ab93ed49b70 | 874 | if(!(dsen_temp_out>0)){ |
umairaftab | 57:7ab93ed49b70 | 875 | dsen_temp_out = dsen_temp_out_prev ; |
umairaftab | 57:7ab93ed49b70 | 876 | } |
umairaftab | 57:7ab93ed49b70 | 877 | else{ |
umairaftab | 57:7ab93ed49b70 | 878 | dsen_temp_out_prev = dsen_temp_out ; |
umairaftab | 57:7ab93ed49b70 | 879 | } |
umairaftab | 57:7ab93ed49b70 | 880 | lcd.printf("Pin:%2.1f Pout:%2.1f",dsen_temp_in,dsen_temp_out); |
umairaftab | 43:cf893fa88690 | 881 | printf("Pi%2.1f Po%2.1f\n\r",dsen_temp_in,dsen_temp_out); |
umairaftab | 38:9f4107db1bff | 882 | wait(15); |
umairaftab | 38:9f4107db1bff | 883 | if ( (pelt_inside_temp-5<=desire_temp_air) && (pelt_inside_temp+5>=desire_temp_air) ){ |
umairaftab | 38:9f4107db1bff | 884 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 885 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 886 | lcd.printf("Exiting Peltier"); |
umairaftab | 38:9f4107db1bff | 887 | lcd.locate(0,1); |
umairaftab | 38:9f4107db1bff | 888 | lcd.printf("Temp within Range"); |
umairaftab | 38:9f4107db1bff | 889 | exit_pelt = true; |
umairaftab | 45:ad99cb94f685 | 890 | wait(5); |
umairaftab | 38:9f4107db1bff | 891 | } |
umairaftab | 38:9f4107db1bff | 892 | } |
umairaftab | 38:9f4107db1bff | 893 | }//pelt while end |
umairaftab | 38:9f4107db1bff | 894 | peltier(false,false,false,false,0); |
umairaftab | 38:9f4107db1bff | 895 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 896 | lcd.locate(0,0); |
umairaftab | 38:9f4107db1bff | 897 | lcd.printf("Pelt Off"); |
umairaftab | 38:9f4107db1bff | 898 | wait(5); |
umairaftab | 38:9f4107db1bff | 899 | lcd.cls(); |
umairaftab | 38:9f4107db1bff | 900 | //lcd.locate(0,1); |
umairaftab | 38:9f4107db1bff | 901 | //lcd.printf("Temp within Range"); |
umairaftab | 38:9f4107db1bff | 902 | |
umairaftab | 38:9f4107db1bff | 903 | }//if block time check end |
umairaftab | 38:9f4107db1bff | 904 | |
umairaftab | 38:9f4107db1bff | 905 | pelt_call_time = ::min ; |
umairaftab | 38:9f4107db1bff | 906 | //pelt_keypad_enable = false; |
umairaftab | 38:9f4107db1bff | 907 | }//Pelt IF keypad block end |
umairaftab | 38:9f4107db1bff | 908 | |
umairaftab | 38:9f4107db1bff | 909 | |
umairaftab | 53:12b7f7b23a31 | 910 | //printf("MIN: %d\n\r",::min); |
umairaftab | 37:892872c3fa96 | 911 | startup_flag = false ; |
umairaftab | 8:2d462919519e | 912 | }//WHILE END |
umairaftab | 8:2d462919519e | 913 | |
umairaftab | 8:2d462919519e | 914 | |
umairaftab | 8:2d462919519e | 915 | } |
umairaftab | 8:2d462919519e | 916 | |
umairaftab | 8:2d462919519e | 917 |