Greenhouse Climate Observation Module
Dependencies: BSP_DISCO_F746NG DHT
main.cpp
- Committer:
- chri721u
- Date:
- 2020-01-22
- Revision:
- 1:4363657c576d
- Parent:
- 0:a5831f680465
- Child:
- 2:739ba85b7a90
File content as of revision 1:4363657c576d:
/* Developer: Christian Andresen Project name: Project Greenhouse Brief description: Microcontroller observing the climate within a greenhouse, and displaying warnings/information as needed. Sensors monitor light levels, as well as temperature and humidity. To simulate an actual greenhouse, LEDs will be used in place of actual influences. Objectives: - Able to set controller location (Which section/greenhouse is it located in) - Able to open window at certain temperature tresholds (For 5 minutes) - Water plants at regular intervals (Twice a day) - Plants must have light for at least 12 hours. If weather is cloudy, artificial lights. - Testmode: Alternate time-tracking system, much faster than 24 hour system. REMEMBER TO RETURN BORROWED LED SOCKETS */ #include "mbed.h" // Mbed header from mbed-os version 5 #include "stm32746g_discovery_lcd.h" // Last updated 27/11/2019 #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; uint8_t text[30]; // Prepare text element for later print to LCD void Window_Open() { 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; } 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() { 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(); } } } int main() { LCD_Start.LCD_Bootup(); // Start multithread tHumid.start(&Humid_Display); tTemp.start(&Temp_Display); while(1) {} }