Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG DHT
Revision 2:739ba85b7a90, committed 2020-01-31
- Comitter:
- chri721u
- Date:
- Fri Jan 31 10:32:08 2020 +0000
- Parent:
- 1:4363657c576d
- Child:
- 3:c21057907d21
- Commit message:
- Working Day/Night Cycle
Changed in this revision
| bootup.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/bootup.cpp Wed Jan 22 07:27:47 2020 +0000
+++ b/bootup.cpp Fri Jan 31 10:32:08 2020 +0000
@@ -1,3 +1,10 @@
+/*
+ Author: Christian Andresen
+ Date: 13/01/2020
+
+ Brief:
+ Bootup screen for the STM32-756g_Discovery LCD monitor.
+*/
#include "mbed.h" // Mbed header from mbed-os version 5
#include "stm32746g_discovery_lcd.h" // Last updated 27/11/2019
#include "bootup.h"
@@ -19,7 +26,7 @@
BSP_LCD_DisplayStringAt(0, 100, (uint8_t *) "HELLDROP GREENHOUSES", CENTER_MODE); // Company
BSP_LCD_DisplayStringAt(0, 150, (uint8_t *) "BIG HARD PLANTS", CENTER_MODE); // Tagline 1
BSP_LCD_DisplayStringAt(0, 175, (uint8_t *) "IN A BIG HARD GREENHOUSE", CENTER_MODE); // Tagline 2
- HAL_Delay(5000); // Delay 10 seconds to simulate actual bootup
+ HAL_Delay(1000); // Delay 1 second to simulate actual bootup
// Prep for display
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
--- 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