Greenhouse Climate Observation Module

Dependencies:   BSP_DISCO_F746NG DHT

main.cpp

Committer:
chri721u
Date:
2020-01-21
Revision:
0:a5831f680465
Child:
1:4363657c576d

File content as of revision 0:a5831f680465:

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

#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 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 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) {
        // Monitor humidity and display results on LCD screen
        float humid = humid_sensor.ReadHumidity();
        wait(1);
        sprintf((char*)text, "Humidity: %.1f", humid);
        BSP_LCD_DisplayStringAt(0, 175, (uint8_t *)&text, CENTER_MODE);
    }
}

int main()
{
    LCD_Start.LCD_Bootup();
    // Start multithread
    tTemp.start(&Temp_Display);
    tHumid.start(&Humid_Display);
}