Greenhouse Climate Observation Module
Dependencies: BSP_DISCO_F746NG DHT
Diff: main.cpp
- Revision:
- 2:739ba85b7a90
- Parent:
- 1:4363657c576d
- Child:
- 3:c21057907d21
diff -r 4363657c576d -r 739ba85b7a90 main.cpp --- a/main.cpp Wed Jan 22 07:27:47 2020 +0000 +++ b/main.cpp Fri Jan 31 10:32:08 2020 +0000 @@ -23,83 +23,66 @@ #include "DHT.h" // Author: Wim De Roeve #include "bootup.h" // Author: Christian Andresen -// Sensor Inputs -AnalogIn temp_sensor(A0); -DHT humid_sensor(A1, DHT22); -AnalogIn light_sensor(A2); - -/* LED Outputs */ -DigitalOut humid_led(D2); // Blue LED -DigitalOut temp_led(D5); // Red LED -DigitalOut water_led(D6); // Blue LED -DigitalOut window_led(D7); // Green LED -DigitalOut light_led(D8); // Yellow LED - // Call Bootup class from bootup.h as LCD_Start bootup LCD_Start; -// Multithreading threads -Thread tTemp; -Thread tHumid; -Thread tLight; -Thread tWater; +/* Inputs */ + +/* Outputs */ +DigitalOut Light_LED(D2); + +/* Multithreads */ +Thread tTimeCounter; -uint8_t text[30]; // Prepare text element for later print to LCD +/* Day & Night */ +void TimeCounter(); +void DayMode(); +void NightMode(); +int timecount = 0; +bool timeofday = 1; -void Window_Open() + +int main() { - for( int a = 1; a < 10; a = a + 1 ) { - window_led = 1; - wait(1); - printf("Window open for %d minutes", a); - } - window_led = 0; -} - -void Water_Spray() -{ - // While humidity is under acceptable levels, this function would spray water. Since it cannot be acurately simultaed, this function will largely remain empty. - humid_led = 1; - wait(0.5); - humid_led = 0; - + LCD_Start.LCD_Bootup(); + tTimeCounter.start(&TimeCounter); + while(1) {} } -void Temp_Display() -{ - while(1) { - // Monitor temperatures and display results on LCD screen - float temp = temp_sensor.read(); - wait(1); - sprintf((char*)text, "Temperature: %.1f C", temp*100/2); - BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)&text, CENTER_MODE); - } -} - -void Humid_Display() +void TimeCounter() { + // Timecounter counts up to one cycle of 720 minutes (Sim 7.20 secs) while(1) { - humid_led = 1; - // Monitor humidity and display results on LCD screen - float humid = humid_sensor.ReadHumidity(); - int dataread = humid_sensor.readData(); - wait(1); - sprintf((char*)text, "Humidity: %.1f", humid); - BSP_LCD_DisplayStringAt(0, 175, (uint8_t *)&text, CENTER_MODE); - - if(humid > 70) { - Window_Open(); - } else if(humid < 50) { - Water_Spray(); + timecount++; + wait(0.01); + printf("%d \n \r", timecount); + if (timecount == 721) { + timeofday = !timeofday; + printf("Time of day is %d \n \r", timeofday); + timecount = 0; + if (timeofday) { + DayMode(); + } else { + NightMode(); + } } } } -int main() +void DayMode() { - LCD_Start.LCD_Bootup(); - // Start multithread - tHumid.start(&Humid_Display); - tTemp.start(&Temp_Display); - while(1) {} + BSP_LCD_Clear(LCD_COLOR_WHITE); + BSP_LCD_SetBackColor(LCD_COLOR_WHITE); + BSP_LCD_SetTextColor(LCD_COLOR_BLACK); + BSP_LCD_DisplayStringAt(0, 100, (uint8_t *) "Time: Day", CENTER_MODE); + Light_LED = 0; } + +void NightMode() +{ + BSP_LCD_Clear(LCD_COLOR_BLACK); + BSP_LCD_SetBackColor(LCD_COLOR_BLACK); + BSP_LCD_SetTextColor(LCD_COLOR_WHITE); + BSP_LCD_DisplayStringAt(0, 100, (uint8_t *) "Time: Night", CENTER_MODE); + Light_LED = 1; +} \ No newline at end of file