Greenhouse Climate Observation Module
Dependencies: BSP_DISCO_F746NG DHT
Diff: main.cpp
- Revision:
- 8:03ba8074d634
- Parent:
- 7:585a66ea498b
diff -r 585a66ea498b -r 03ba8074d634 main.cpp --- a/main.cpp Wed Feb 05 12:28:55 2020 +0000 +++ b/main.cpp Wed Feb 05 13:56:12 2020 +0000 @@ -62,7 +62,7 @@ float humid; /* Greenhouse mechanisms */ -void Vent_Air(); +void Vent_Air(); void Heat_Lamp(); void Dehumidifier(); void Spray_Water(); @@ -74,7 +74,6 @@ { cout << "Enter Greenhouse ID: \n \r"; cin >> location_id; - cout << "Greenhouse ID is: " << location_id; } int main() @@ -111,11 +110,12 @@ void TimeCounter() { - // Timecounter counts up to one cycle of 720 minutes (Sim 7.20 secs) + // Timecounter counts up to one cycle of + // 720 minutes if not in Simulation mode while(1) { if(simmode) { timecount++; - wait(0.01); + wait(0.01); // One tenth of a second per tic if (timecount == 721) { timeofday = !timeofday; printf("Time of day is %d \n \r", timeofday); @@ -128,7 +128,7 @@ } } else if(simmode == 0) { timecount++; - wait(1); + wait(60); // 1 minute per tic if (timecount == 721) { timeofday = !timeofday; timecount = 0; @@ -181,24 +181,32 @@ void Temp_Check() { while(1) { - temp = Temp_Sensor.read() * 100 / 2; // Read temperature sensor input. Since this is flawed, correct to adjust. - if(timeofday) { // If it's daytime, keep temps between 25 and 30 celsius + temp = Temp_Sensor.read() * 100 / 2; + // Read temperature sensor input. Since this is flawed, correct to adjust. + if(timeofday) { + // If it's daytime, keep temps between 25 and 30 celsius if (temp >= 25 && temp <= 30) { - printf("Greenhouse temperature within acceptable parameters \n \r"); - wait(1); + Temp_LED = 1; } else if (temp < 25) { - Heat_Lamp(); // Raise temperature by turning on the heat lamps in the greenhouse + Temp_LED = 0; + Heat_Lamp(); + // Raise temperature by turning on the heat lamps in the greenhouse } else if (temp > 30) { - Vent_Air(); // Reduce temperature by venting the hot air out of the greenhouse + + Temp_LED = 0; + Vent_Air(); + // Reduce temperature by venting the hot air out of the greenhouse } - } else if(timeofday == false) { // If it's nighttime, keep temps between 15 and 20 + } else if(timeofday == false) { + // If it's nighttime, keep temps between 15 and 20 if (temp >= 15 && temp <= 20) { Temp_LED = 1; - wait(1); } else if (temp < 15) { + Temp_LED = 0; Heat_Lamp(); } else if (temp > 20) { + Temp_LED = 0; Vent_Air(); } } @@ -211,10 +219,12 @@ humid = Humid_Sensor.ReadHumidity(); int dataread = Humid_Sensor.readData(); // No idea why, but the humidity won't display on screen without it. if (humid >= 55 && humid <= 65) { // Check if humidity is within acceptable parameters (55% - 65%) - printf("Greenhouse humidity is within acceptable parameters \n \r"); + Humid_LED = 1; } else if (humid < 55) { + Humid_LED = 0; Spray_Water(); // Raise humidity by spraying water into the plants and greenhouse. } else if ( humid > 65) { + Humid_LED = 0; Dehumidifier(); // Lower humidity by dehumidifying the greenhouse. } }