Greenhouse Climate Observation Module

Dependencies:   BSP_DISCO_F746NG DHT

Committer:
chri721u
Date:
Fri Jan 31 10:32:08 2020 +0000
Revision:
2:739ba85b7a90
Parent:
1:4363657c576d
Child:
3:c21057907d21
Working Day/Night Cycle

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chri721u 0:a5831f680465 1 /*
chri721u 0:a5831f680465 2 Developer: Christian Andresen
chri721u 0:a5831f680465 3
chri721u 0:a5831f680465 4 Project name: Project Greenhouse
chri721u 0:a5831f680465 5
chri721u 0:a5831f680465 6 Brief description:
chri721u 0:a5831f680465 7 Microcontroller observing the climate within a greenhouse, and displaying warnings/information as needed.
chri721u 0:a5831f680465 8 Sensors monitor light levels, as well as temperature and humidity.
chri721u 0:a5831f680465 9 To simulate an actual greenhouse, LEDs will be used in place of actual influences.
chri721u 0:a5831f680465 10
chri721u 0:a5831f680465 11 Objectives:
chri721u 0:a5831f680465 12 - Able to set controller location (Which section/greenhouse is it located in)
chri721u 0:a5831f680465 13 - Able to open window at certain temperature tresholds (For 5 minutes)
chri721u 0:a5831f680465 14 - Water plants at regular intervals (Twice a day)
chri721u 0:a5831f680465 15 - Plants must have light for at least 12 hours. If weather is cloudy, artificial lights.
chri721u 0:a5831f680465 16 - Testmode: Alternate time-tracking system, much faster than 24 hour system.
chri721u 1:4363657c576d 17
chri721u 1:4363657c576d 18 REMEMBER TO RETURN BORROWED LED SOCKETS
chri721u 0:a5831f680465 19 */
chri721u 0:a5831f680465 20
chri721u 0:a5831f680465 21 #include "mbed.h" // Mbed header from mbed-os version 5
chri721u 0:a5831f680465 22 #include "stm32746g_discovery_lcd.h" // Last updated 27/11/2019
chri721u 0:a5831f680465 23 #include "DHT.h" // Author: Wim De Roeve
chri721u 0:a5831f680465 24 #include "bootup.h" // Author: Christian Andresen
chri721u 0:a5831f680465 25
chri721u 0:a5831f680465 26 // Call Bootup class from bootup.h as LCD_Start
chri721u 0:a5831f680465 27 bootup LCD_Start;
chri721u 0:a5831f680465 28
chri721u 2:739ba85b7a90 29 /* Inputs */
chri721u 2:739ba85b7a90 30
chri721u 2:739ba85b7a90 31 /* Outputs */
chri721u 2:739ba85b7a90 32 DigitalOut Light_LED(D2);
chri721u 2:739ba85b7a90 33
chri721u 2:739ba85b7a90 34 /* Multithreads */
chri721u 2:739ba85b7a90 35 Thread tTimeCounter;
chri721u 0:a5831f680465 36
chri721u 2:739ba85b7a90 37 /* Day & Night */
chri721u 2:739ba85b7a90 38 void TimeCounter();
chri721u 2:739ba85b7a90 39 void DayMode();
chri721u 2:739ba85b7a90 40 void NightMode();
chri721u 2:739ba85b7a90 41 int timecount = 0;
chri721u 2:739ba85b7a90 42 bool timeofday = 1;
chri721u 0:a5831f680465 43
chri721u 2:739ba85b7a90 44
chri721u 2:739ba85b7a90 45 int main()
chri721u 0:a5831f680465 46 {
chri721u 2:739ba85b7a90 47 LCD_Start.LCD_Bootup();
chri721u 2:739ba85b7a90 48 tTimeCounter.start(&TimeCounter);
chri721u 2:739ba85b7a90 49 while(1) {}
chri721u 1:4363657c576d 50 }
chri721u 1:4363657c576d 51
chri721u 2:739ba85b7a90 52 void TimeCounter()
chri721u 0:a5831f680465 53 {
chri721u 2:739ba85b7a90 54 // Timecounter counts up to one cycle of 720 minutes (Sim 7.20 secs)
chri721u 0:a5831f680465 55 while(1) {
chri721u 2:739ba85b7a90 56 timecount++;
chri721u 2:739ba85b7a90 57 wait(0.01);
chri721u 2:739ba85b7a90 58 printf("%d \n \r", timecount);
chri721u 2:739ba85b7a90 59 if (timecount == 721) {
chri721u 2:739ba85b7a90 60 timeofday = !timeofday;
chri721u 2:739ba85b7a90 61 printf("Time of day is %d \n \r", timeofday);
chri721u 2:739ba85b7a90 62 timecount = 0;
chri721u 2:739ba85b7a90 63 if (timeofday) {
chri721u 2:739ba85b7a90 64 DayMode();
chri721u 2:739ba85b7a90 65 } else {
chri721u 2:739ba85b7a90 66 NightMode();
chri721u 2:739ba85b7a90 67 }
chri721u 1:4363657c576d 68 }
chri721u 0:a5831f680465 69 }
chri721u 0:a5831f680465 70 }
chri721u 0:a5831f680465 71
chri721u 2:739ba85b7a90 72 void DayMode()
chri721u 0:a5831f680465 73 {
chri721u 2:739ba85b7a90 74 BSP_LCD_Clear(LCD_COLOR_WHITE);
chri721u 2:739ba85b7a90 75 BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
chri721u 2:739ba85b7a90 76 BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
chri721u 2:739ba85b7a90 77 BSP_LCD_DisplayStringAt(0, 100, (uint8_t *) "Time: Day", CENTER_MODE);
chri721u 2:739ba85b7a90 78 Light_LED = 0;
chri721u 0:a5831f680465 79 }
chri721u 2:739ba85b7a90 80
chri721u 2:739ba85b7a90 81 void NightMode()
chri721u 2:739ba85b7a90 82 {
chri721u 2:739ba85b7a90 83 BSP_LCD_Clear(LCD_COLOR_BLACK);
chri721u 2:739ba85b7a90 84 BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
chri721u 2:739ba85b7a90 85 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
chri721u 2:739ba85b7a90 86 BSP_LCD_DisplayStringAt(0, 100, (uint8_t *) "Time: Night", CENTER_MODE);
chri721u 2:739ba85b7a90 87 Light_LED = 1;
chri721u 2:739ba85b7a90 88 }