Greenhouse Climate Observation Module

Dependencies:   BSP_DISCO_F746NG DHT

main.cpp

Committer:
chri721u
Date:
2020-01-31
Revision:
2:739ba85b7a90
Parent:
1:4363657c576d
Child:
3:c21057907d21

File content as of revision 2:739ba85b7a90:

/*
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

// Call Bootup class from bootup.h as LCD_Start
bootup LCD_Start;

/* Inputs */

/* Outputs */
DigitalOut Light_LED(D2);

/* Multithreads */
Thread tTimeCounter;

/* Day & Night */
void TimeCounter();
void DayMode();
void NightMode();
int timecount = 0;
bool timeofday = 1;


int main()
{
    LCD_Start.LCD_Bootup();
    tTimeCounter.start(&TimeCounter);
    while(1) {}
}

void TimeCounter()
{
    // Timecounter counts up to one cycle of 720 minutes (Sim 7.20 secs)
    while(1) {
        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();
            }
        }
    }
}

void DayMode()
{
    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;
}